I have heard the term 'list difference' (\\)
operator in Haskell but still don't quite know how to get my head around it. Any examples or ideas?
The (\\)
operator (and the difference
function) implements set difference, so, if you have two lists, a
and b
, it returns only those elements of a
that are not in b
, as illustrated:
Simply put, it takes two lists, goes through the second and for each item, removes the first instance of the same item from the first list.
> [1..10] \\ [2, 3, 5, 8]
[1,4,6,7,9,10]
> [1, 2, 1, 2, 1, 2] \\ [2]
[1,1,2,1,2]
> [1, 2, 1, 2, 1, 2] \\ [2, 2]
[1,1,1,2]
> [1, 2, 1, 2, 1, 2] \\ [2, 2, 1]
[1,1,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