I’ve always though it a shame that there is no in language short hand syntax for maps and sets in F#, something like {{foo = 1; bar = 2}} and {#1, 2#} – but having a very flexible language at my disposal I set out to find some way to achieve this, mostly for fun – but maybe someone will find a practical use of it.
let (<&) (map:Map<_, _>) (key, item) = Map.add key item map
let (<!) (set:Set<_>) item = Set.add item set
let map = Map.empty
let set = Set.empty
//Example
let mySet = set <! 1 <! 2
let myMap = map <& ("foo", 1) <& ("bar", 2)
I’m sure there are better ways to do this in F# and someone smarter then me will point it out, which is half the reason I’m posting this.