我想要类似的东西
splitBy pred list = ( filter pred list, filter (not . pred) list )
但是一口气。
最佳答案
您正在从partition
寻找 Data.List
函数:
partition :: (a -> Bool) -> [a] -> ([a], [a])
可以使用fold很好地实现它:
splitBy pred = foldr f ([], [])
where f x ~(yes, no) = if pred x then (x : yes, no)
else (yes, x : no)
关于list - Haskell过滤器/拆分列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14969827/