nubBy package:data-ordlist

The nubBy function is the greedy algorithm that returns a sublist of its input such that:
isSortedBy pred (nubBy pred xs) == True
This is true for all lists, not just ordered lists, and all binary predicates, not just total orders. On infinite lists, this statement is true in a certain mathematical sense, but not a computational one.