Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell removes all occurrences of a given value from within a list of lists

Tags:

haskell

I would like to remove all occurrences of a given value from within a list of lists. For example, input:

'a' ["abc", "bc", "aa"] 

output:

 ["bc", "bc", ""]

so far:

remove :: Eq a => a -> [[a ]] -> [[a ]]
remove y xs = filter(\x -> x/= y) xs

I'm getting an error, thank you in advance.

like image 455
ErHunt Avatar asked Apr 07 '12 01:04

ErHunt


1 Answers

You need to map over the outer lists.

remove y xs = map (filter(\x -> x/= y)) xs

You don't actually need a lambda here, nicer:

remove y xs = map (filter(/=y)) xs
like image 156
leftaroundabout Avatar answered Nov 07 '22 19:11

leftaroundabout