I wrote the code but looks ugly.
Image there are two seqs like:
let x = [(1,"x");(2,"y")]
let y = [(1, "xx", "xxx");(2,"yy","yyy")]
The elements are tuples but not the same shape.
The result need to be [(1, "x", "xx", "xxx");(2, "y", "yy", "yyy")].
The first element in the tuple is the key here.
The code I wrote used map like:
let x = [(1,"x");(2,"y")]
let y = [(1, "xx", "xxx");(2,"yy","yyy")]
let mapY = y |> Seq.map (fun (a,b,c) -> (a, (b, c))) |> Map.ofSeq
let r = [
for (k,v) in x do
let (v1,v2) = mapY |> Map.tryFind k |> Option.orElse (Some ("","")) |> Option.get
yield (k, v, v1, v2)
]
printfn "%A" r
not so gracefully.
So I wonder any better solution?(The tuple element in the question can be seq type, tuple just for example).
The key question is how to merge two seq by key gracefully.