Skip to content

F# list extensions for converting between F# and C# lists

License

Notifications You must be signed in to change notification settings

dbrattli/FSharp.ListEx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSharp.ListEx

F# List extensions for converting between F# and C# lists. It's really not that difficult but enough friction to make you search Stack Overflow.

How to use

open FSharp.ListEx

let fsList = [1; 2; 3]

// Convert F# List to C# List.
let csList = ResizeArray fsList           // Without FSharp.ListEx
let csList = List.toResizeArray fsList    // F# List module (FSharp.ListEx)
let csList = List.toCSharpList fsList     // Alias for List.toResizeArray (FSharp.ListEx)

// Convert C# List to F# List.
let fsList = List.ofSeq xs                // Without FSharp.ListEx
let fsList = List.ofResizeArray csList    // F# List module (FSharp.ListEx)
let fsList = List.ofEnumerable csList     // Alias for List.ofResizeArray (FSharp.ListEx)

// Convert C# List to F# List.
let fsList = Seq.toList csList            // Without FSharp.ListEx
let fsList = csList.ToFSharpList ()       // List (C#) extension method (FSharp.ListEx)

// Convert IEnumerable to F# List (can be used from C#).
let fsList = ListModule.OfSeq(xs)         // Without FSharp.ListEx

let xs = csList :> IEnumerable<_>
let fsList = xs.ToFSharpList ()           // IEnumerable extension method (FSharp.ListEx)

Map (bonus)

let fsMap = Map [("a", 10); ("b", 20) ]

// Convert F# Map to C# Dictionary and IDictionary
let csDict = Map.toDictionary fsMap
let csIDict = Map.toIDictionary fsMap

// Convert C# Dictionary and IDictionary to F# Map
let fsMap = Map.ofDictionary csDict
let fsMap = Map.ofDictionary csIDict

About

F# list extensions for converting between F# and C# lists

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages