dictionary - Swap key and value in a map in fsharp -


how create new map similar original one, swapped keys , values in fsharp? example, have this

let map1 = [("a", "1"); ("b", "2"); ("c", "3");] |> map.oflist 

and want this:

let map2 = [("1", "a"); ("2", "b"); ("3", "c");] |> map.oflist 

thank help!

perhaps approach decision:

let map1 = map.oflist [("a", "1"); ("b", "2"); ("c", "3")]  map1 |> printfn "%a"  let rev map: map<string,string> =        map.fold (fun m key value -> m.add(value,key)) map.empty map  rev map1 |> printfn "%a" 

print:

map [("a", "1"); ("b", "2"); ("c", "3")] map [("1", "a"); ("2", "b"); ("3", "c")] 

link: http://ideone.com/cfn2yh


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -