0
votes

I am trying to convert a list of tuples(A*B) into a list of (B). How would I approach this? As I ultimately am trying to get the second value from a map so therefore I first turned it into a list but I am struggling removing the first elements from the list as I do not need them.

I got something like this:

map |> Map.toList

now I figured I had to use List.filter but I do not see how to set up a bool expression to evict the 1st values from list so maybe its better to create a entirely new list with the seconds values.

Any help would be appreciated!

1

1 Answers

2
votes

Easy:

["a", 1; "b", 2] 
|> List.map snd 
|> printfn "%A"

Another way:

["a", 1; "b", 2] 
|> List.map (fun (a, b) -> b)
|> printfn "%A"

By the way the module Map refers to a different type than List. A Map is an immutable Dictionary: https://msdn.microsoft.com/visualfsharpdocs/conceptual/collections.map%5b%27key%2c%27value%5d-class-%5bfsharp%5d