Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string[][][] to string[][] in f#

I'm having some troubles with F# because i'm learning. I have something like the next code:

let A = [| [| [|"1";"Albert"|];[|"2";"Ben"|] |];[| [|"1";"Albert"|];[|"3";"Carl"|] |] |]

(Type A: string[][][])

I'm trying to convert A to:

let B = [| [|"1"; "Albert" |] ; [| "2"; "Ben"|] ; [| "3"; "Carl"|] |]

(Type B: string[][])

I don't know how to do this. I've been trying some for and recursive function but I don't get it.

like image 414
aaossa Avatar asked Mar 16 '26 13:03

aaossa


1 Answers

You could use Array.concat to turn the string[][][] into string[][], and then Seq.distinct to remove the duplicate string arrays.

let b = 
    [| [| [|"1";"Albert"|];[|"2";"Ben"|] |];[| [|"1";"Albert"|];[|"3";"Carl"|] |] |]
        |> Array.concat
        |> Seq.distinct
        |> Seq.toArray
like image 156
Matthew Mcveigh Avatar answered Mar 18 '26 13:03

Matthew Mcveigh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!