With the following data (random strings):
let data =
[
["shi"; "cjwocij"; "cjwijo"]
["abs"; "djw"; "djwjdwojdow"]
["djido"; "dkwpkw"; "dpfkpeoep"]
]
I would like to calculate the max length by column. I can transform the data into a list of lists of lengths:
data |> List.map (fun r -> r |> List.map (fun x -> x.Length))
index value
0 [ 3; 7; 6 ]
1 [ 3; 3; 11 ]
2 [ 5; 6; 9 ]
but ultimately I'd like to reduce it to:
[5; 7; 11]
by taking the max of each column
I thought I could do a fold and take the first row as a starting point, but it looks like it'll be quite convoluted.
For context: it's for a function that will take a grid and display it with proper spacing / formatting; all rows must have the same number of elements.