Fast F#: Intro to Maps
HTML-код
- Опубликовано: 28 сен 2024
- The Map collection in F# is an immutable Key/Value collection. Let's learn how to work with them!
=== Contact ===
Email: hi@fastfsharp.com
Mastadon: mastodon.sdf.o...
Twitter: / fastfsharp
=== Tags ===
Tags: #fsharp, #dotnet
Great explaining as always. This is interesting. This is not even complaining. Its just removing the first bit and replacing it with the last one.
let a = Map [ 1, "a"; 2, "b";1,"c" ]
a[1]
> let a = Map [ 1, "a"; 2, "b";1,"c" ]
- a[1];;
val a: Map = map [(1, "c"); (2, "b")]
val it: string = "c"
But why ist that?
Because when you are creating a map, the "last write wins". If you have several instances of the same key, that last key/value pair will be what is stored in the Map.