tags:

views:

79

answers:

1

Given this:

[
    ("A","A122");
    ("A","A123");
    ("B","B122");
    ("B","B123");
    ("C","C122");
]

Is there a standard function to get this?

[
    ("A",["A122";"A123"]);
    ("B",["B122";"B123"]);
    ("C",["C122"])
]

I thought of Seq.distinctBy, List.partition, Set, Map, but none of them seem to be what I'm looking for.

Thanks... while I'm waiting, I'll try to roll my own :)

+4  A: 

Silly me, I didn't notice Seq.groupBy!

[
    ("A","A122");
    ("A","A123");
    ("B","B122");
    ("B","B123");
    ("C","C122");
]
 |> Seq.groupBy (fun (a, b) -> a)
 |> Seq.map (fun (a, b) -> (a, Seq.map snd b))

Output :

seq
[("A", seq ["A122"; "A123"]); ("B", seq ["B122"; "B123"]);
 ("C", seq ["C122"])]
Benjol