2015-09-25 137 views
3

的名单目前我有这个功能:过滤掉空字符串列表

removeNull strList = filter (not . null) strList 

但我需要使用地图(我认为)将其应用到一个列表的列表,但我发现型错误。

在GHCI,功能过滤器这个正确:

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

但这并不过滤:

removeNull [["i", "", "b"], ["i", "", "b"]] 
[["i","","b"],["i","","b"]] 
+3

'fmap removeNull [[..]]' – karakfa

回答

7

只需使用map到过滤器适用于每个子列表,例如

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