Created
August 15, 2012 21:34
-
-
Save theburningmonk/3363893 to your computer and use it in GitHub Desktop.
F# - converting a C# dictionary to a Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let toMap dictionary = | |
(dictionary :> seq<_>) | |
|> Seq.map (|KeyValue|) | |
|> Map.ofSeq |
Two suggestions:
- Mark the function as
inline
so that callers oftoMap
will not affect the F# type inference process and fix the generic arguments - The upcast is not necessary as
IDictionary<K, V>
already implementsIEnumerable<KeyValuePair<K, V>>
let inline toMap kvps =
kvps
|> Seq.map (|KeyValue|)
|> Map.ofSeq
I'm fairly new to F# and wondering - how to get to know with built-in active patterns like this?
I'm fairly new to F# and wondering - how to get to know with built-in active patterns like this?
Same
I'm fairly new to F# and wondering - how to get to know with built-in active patterns like this?
This site can be helpful.
https://fsharp.github.io/fsharp-core-docs/
For example, here you can check all Map operations.
https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-mapmodule.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you don't need the () around the top part.