Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Haskell

Idiom #136 Remove all occurrences of a value from a list

Remove all occurrences of the value x from list items.
This will alter the original list or return a new list, depending on which is more idiomatic.

filter (/= x) items

This returns a new list.
/= is the inequality operator of Haskell. Note that its usage requires x's type to instantiate the Eq type-class.
(/= x) is a shorthand for the lambda (\e -> e /= x).
(remove #{x} items)

Puts the x value in a set that serves as simple predicate

New implementation...