Oluwagbemi Kadri
Oluwagbemi Kadri

Reputation: 469

How to convert int list list list to (int * int) list in f#

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

Answers (1)

dumetrulo
dumetrulo

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

Related Questions