haskell从列表列表中删除所有出现的给定值 [英] haskell removes all occurrences of a given value from within a list of lists
本文介绍了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", ""]
到目前为止:
remove :: Eq a => a -> [[a ]] -> [[a ]]
remove y xs = filter(\x -> x/= y) xs
我收到一个错误,提前谢谢。
I'm getting an error, thank you in advance.
推荐答案
您需要映射到外部列表。
You need to map over the outer lists.
remove y xs = map (filter(\x -> x/= y)) xs
您实际上并不需要lambda表达式,更好:
You don't actually need a lambda here, nicer:
remove y xs = map (filter(/=y)) xs
这篇关于haskell从列表列表中删除所有出现的给定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文