added partiion function
This commit is contained in:
parent
e338e3a738
commit
c85e2ffecd
1 changed files with 10 additions and 0 deletions
10
Utils.hs
10
Utils.hs
|
@ -3,3 +3,13 @@ module Utils where
|
||||||
|
|
||||||
symbolic = (`elem` symbolic_ops)
|
symbolic = (`elem` symbolic_ops)
|
||||||
symbolic_ops = "!@#$%^&*+./<=>?\\^|:-~"
|
symbolic_ops = "!@#$%^&*+./<=>?\\^|:-~"
|
||||||
|
|
||||||
|
-- doing 'partition f xs = (filter f xs, filter (not . f) xs)' is too
|
||||||
|
-- slow, cuz it would run same test twice on every paramter. I might
|
||||||
|
-- be wrong tho
|
||||||
|
partition :: (a -> Bool) -> [a] -> ([a], [a])
|
||||||
|
partition _ [] = ([], [])
|
||||||
|
partition f (x:xs)
|
||||||
|
| f x = (x:pass, fail)
|
||||||
|
| otherwise = (pass, x:fail)
|
||||||
|
where (pass, fail) = partition f xs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue