I have 4 arrays of different data. For the first array of string, I want to delete the duplicate element and get the results of array of unique tuples with 4 elements.
For example, let’s say the arrays are:
let dupA1 = [| "A"; "B"; "C"; "D"; "A" |]
let dupA2 = [| 1; 2; 3; 4; 1 |]
let dupA3 = [| 1.0M; 2.0M; 3.0M; 4.0M; 1.0M |]
let dupA4 = [| 1L; 2L; 3L; 4L; 1L |]
I want the result to be:
let uniqueArray = [| ("A", 1, 1.0M, 1L); ("B", 2, 2.0M, 2L); ("C", 3, 3.0M, 3L); ("D",4,
Thanks to abatishchev for his great code, now I have this answer:
let zip4 a (b : _ []) (c : _ []) (d : _ []) =
Array.init (Array.length a) (fun i -> a.[i], b.[i], c.[i], d.[i])
let uniqueArray = zip4 dupA1 dupA2 dupA3 dupA4 |> Seq.distinct |> Seq.toArray
However, further more, I want to find the result of each array from the unique array.
let uniqueArray = [| ("A", 1, 1.0M, 1L); ("B", 2, 2.0M, 2L); ("C", 3, 3.0M, 3L); ("D",4, 4.0M, 4L) |]
I want the following 4 arrays from uniqeArray:
let uniqA1 = [| "A"; "B"; "C"; "D" |]
let uniqA2 = [| 1; 2; 3; 4 |]
let uniqA3 = [| 1.0M; 2.0M; 3.0M; 4.0M |]
let uniqA4 = [| 1L; 2L; 3L; 4L |]
I tried the following code:
let [| uniqA1, uniqA2, uniqA3, uniqA4 |] = uniqueArray
First, I get the compiler warning:
Warning 1
Incomplete pattern matches on this expression. For example, the value ‘[|_; _|]‘ may indicate a case not covered by the pattern(s).
After I used #nowarn "25", during the run time, I got the following error:
Microsoft.FSharp.Core.MatchFailureException was unhandled
Message: An unhandled exception of type 'Microsoft.FSharp.Core.MatchFailureException' occurred in Program.exe
Please help me with the further requirements.
You now need
unzip4:Then you can do: