Logo

Programming-Idioms

History of Idiom 135 > diff from v8 to v9

Edit summary for version 9 by Alekzcb:
New Haskell implementation by user [Alekzcb]

Version 8

2016-08-23, 13:20:33

Version 9

2017-09-21, 18:57:13

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Code
removeOne :: Eq a => a -> [a] -> [a]
removeOne _ [] = []
removeOne x (i:items)
   | x == i = items
   | otherwise = i : (removeOne x items)
Comments bubble
Restriction Eq required to use (==).