Logo

Programming-Idioms

History of Idiom 135 > diff from v20 to v21

Edit summary for version 21 by sjakobi:
[Haskell] No new definition needed

Version 20

2019-09-26, 16:37:07

Version 21

2019-09-26, 16:44:12

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.

Imports
Imports
import Data.List
Code
removeOne :: Eq a => a -> [a] -> [a]
removeOne _ [] = []
removeOne x (i:items)
   | x == i = items
   | otherwise = i : (removeOne x items)
Code
delete
Comments bubble
Restriction Eq required to use (==).
Comments bubble
base contains a function that does this.
Doc URL
http://hackage.haskell.org/package/base/docs/Data-List.html#v:delete