sanic
sanic

Reputation: 2085

Filter out null string in a list of lists

Currently I have this function:

removeNull strList = filter (not . null) strList

But I need to use map (I assume) to apply it to a list of lists, but I'm getting type errors.

In GHCi, the functions filters this correctly:

removeNull ["i", "", "b"]
["i","b"]

But this doesn't filter:

removeNull [["i", "", "b"], ["i", "", "b"]]
[["i","","b"],["i","","b"]]

Upvotes: 3

Views: 98

Answers (1)

Rizier123
Rizier123

Reputation: 59701

Simply use map to apply your filter to each subList, e.g.

removeNull strList = map (filter (not . null))  strList
                   //^^^ See here

Upvotes: 7

Related Questions