I am familiar with the nub
function on lists containing numbers, characters, or strings, but
can someone explain to me how I can use the nub
function from Data.List
on a list of pairs?
Example:
[('a', 3),( 'b', 2),('a', 1),('b', 4)]
to
[('a', 3),('b', 2)]
As you can see, I want to remove all pairs where the key from the pair (key, value) is already in the list.
Here's one way:
Prelude Data.List> nubBy (\(x,_) (x', _) -> x == x') [('a',1),('b',2),('b',3)]
[('a',1),('b',2)]
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