6

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.

1 Answer 1

10

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
2
  • 3
    you can also drop xs on both sides Apr 7, 2012 at 10:29
  • 3
    Or even map . filter . (/=)
    – Vitus
    Apr 7, 2012 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.