Okay so I'm lost on this one. I have a list of objects. Each object as a non-unique ID in it. I want to group on this ID but for the life of me I can't figure out how to do this.
This is what I have
type fooObject = {
Id : int
Info : string
}
let fooObjects: fooObject list
The data might look something like this
[ { Id = 1 ; Data = "foo" } ; { Id = 1 ; Data = "also foo" } ; { Id = 2 ; Data = "Not foo" } ]
I would like something like
let fooObjectsGroupedById : fooObject list list
So the final result would look like this
[ [{ Id = 1 ; Data = "foo" } ; { Id = 1 ; Data = "also foo" } ] ; [{ Id = 2 ; Data = "Not foo" }]]
Use List.groupBy
:
let groupById fooObjects =
List.groupBy (fun foo -> foo.Id) fooObjects
|> List.map snd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With