Reputation: 469
If I want to Convert a list [[[0; 5]; [1; 5]; [2; 3]]] to a tuple list [(0, 5); (1, 5); (2, 3)] using f# or pattern matching in f# please how do I do this?
Upvotes: 1
Views: 202
Reputation: 1991
I would flatten the outer level of the list (by concatenating the second level lists), then transform the inner lists into tuples using map
:
let transform lst =
lst
|> List.concat
|> List.map (function
| [a; b] -> (a, b)
| _ -> failwith "Incorrect list syntax")
Upvotes: 3