nub package:xmonad-contrib

The nub function removes duplicate elements from a list. In particular, it keeps only the first occurrence of each element. (The name nub means `essence'.) It is a special case of nubBy, which allows the programmer to supply their own equality test. If there exists instance Ord a, it's faster to use nubOrd from the containers package (link to the latest online documentation), which takes only <math> time where d is the number of distinct elements in the list. Another approach to speed up nub is to use map Data.List.NonEmpty.head . Data.List.NonEmpty.group . sort, which takes <math> time, requires instance Ord a and doesn't preserve the order.

Examples

>>> nub [1,2,3,4,3,2,1,2,4,3,5]
[1,2,3,4,5]
>>> nub "hello, world!"
"helo, wrd!"
Given a list of screens, remove all duplicated screens and screens that are entirely contained within another.
The nubBy function behaves just like nub, except it uses a user-supplied equality predicate instead of the overloaded (==) function.

Examples

>>> nubBy (\x y -> mod x 3 == mod y 3) [1,2,4,5,6]
[1,2,6]
>>> nubBy (/=) [2, 7, 1, 8, 2, 8, 1, 8, 2, 8]
[2,2,2]
>>> nubBy (>) [1, 2, 3, 2, 1, 5, 4, 5, 3, 2]
[1,2,3,5,5]