Created
December 19, 2021 19:27
-
-
Save ebresafegaga/bff4e2db8d71f57bdde4c6ed0f3d8358 to your computer and use it in GitHub Desktop.
Traspose now!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec transpose xss = | |
match xss with | |
| [] :: _ | [] -> [] | |
| xs :: xss -> | |
let hds = List.map List.hd xss in | |
let tls = List.map List.tl xss in | |
let hd = List.hd xs in | |
let tl = List.tl xs in | |
(hd :: hds) :: transpose (tl :: tls) | |
let rec transpose1 xss = | |
match xss with | |
| [] -> [] (* we would only get here if we're actually given an empty list *) | |
| [xs] -> xs |> List.map (fun elem -> [elem]) | |
| xs :: xss -> | |
let almost = transpose1 xss in | |
List.combine xs almost | |
|> List.map (fun (x, xs) -> x :: xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment