Given a record like
data Foo = Foo { fooName :: Text, fooAge :: Int, fooCity :: Text }
With a list of such elements, is there a function to remove duplicates on a subset of fields only, on the model of this hypothetical removeDupBy function?
foos =
[
Foo "john" 32 "London",
Foo "joe" 18 "New York",
Foo "john" 22 "Paris",
Foo "john" 32 "Madrid",
Foo "joe" 17 "Los Angeles",
Foo "joe" 18 "Berlin"
]
> removeDupBy (\(Foo f) -> (fooName, fooAge)) foos
[
Foo "john" 32 "London",
Foo "joe" 18 "New York",
Foo "john" 22 "Paris",
Foo "joe" 17 "Los Angeles"
]
I could implement my own but would prefer using one from a well-established library, which will probably be much more performant and be much more resilient against edge cases. I was thinking of using nub but I'm not sure how to map the actual Foo elements to the tuples (fooName, fooAge) that nub would filter out.