added partiion function

This commit is contained in:
Pranshu Sharma 2025-05-25 18:44:48 +10:00
parent e338e3a738
commit c85e2ffecd

View file

@ -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