Haskell removes all occurrences of a given value from a list of lists.

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

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

exit:

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

:

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

I get an error, thanks in advance.

+6
source share
1 answer

You need to display external lists.

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

Actually you don't need lambda, better:

 remove y xs = map (filter(/=y)) xs 
+10
source

Source: https://habr.com/ru/post/912639/


All Articles