Hash join: Difference between revisions
Content added Content deleted
No edit summary |
(Added F#) |
||
Line 830: | Line 830: | ||
{{28,"Glory"},{"Glory","Buffy"}}] |
{{28,"Glory"},{"Glory","Buffy"}}] |
||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
<lang fsharp>[<EntryPoint>] |
|||
let main argv = |
|||
let table1 = [27, "Jonah"; |
|||
18, "Alan"; |
|||
28, "Glory"; |
|||
18, "Popeye"; |
|||
28, "Alan"] |
|||
let table2 = ["Jonah", "Whales"; |
|||
"Jonah", "Spiders"; |
|||
"Alan", "Ghosts"; |
|||
"Alan", "Zombies"; |
|||
"Glory", "Buffy"] |
|||
let hash = Seq.groupBy (fun r -> snd r) table1 |
|||
table2 |
|||
|> Seq.collect (fun r -> |
|||
hash |
|||
|> Seq.collect (fun kv -> |
|||
if (fst r) <> (fst kv) then [] |
|||
else (Seq.map (fun x -> (x, r)) (snd kv)) |> Seq.toList) |
|||
) |
|||
|> Seq.toList |
|||
|> printfn "%A" |
|||
0</lang> |
|||
{{out}} |
|||
<pre>[((27, "Jonah"), ("Jonah", "Whales")); ((27, "Jonah"), ("Jonah", "Spiders")); |
|||
((18, "Alan"), ("Alan", "Ghosts")); ((28, "Alan"), ("Alan", "Ghosts")); |
|||
((18, "Alan"), ("Alan", "Zombies")); ((28, "Alan"), ("Alan", "Zombies")); |
|||
((28, "Glory"), ("Glory", "Buffy"))]</pre> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |