Commit 308cb59e authored by simonpj@microsoft.com's avatar simonpj@microsoft.com

Add new utility function, partitionWith

parent 70820d6e
......@@ -12,7 +12,7 @@ module Util (
zipLazy, stretchZipWith,
mapFst, mapSnd,
mapAndUnzip, mapAndUnzip3,
nOfThem, filterOut,
nOfThem, filterOut, partitionWith,
lengthExceeds, lengthIs, lengthAtLeast,
listLengthCmp, atLength, equalLength, compareLength,
......@@ -168,6 +168,15 @@ filterOut :: (a->Bool) -> [a] -> [a]
filterOut p [] = []
filterOut p (x:xs) | p x = filterOut p xs
| otherwise = x : filterOut p xs
partitionWith :: (a -> Either b c) -> [a] -> ([b], [c])
partitionWith f [] = ([],[])
partitionWith f (x:xs) = case f x of
Left b -> (b:bs, cs)
Right c -> (bs, c:cs)
where
(bs,cs) = partitionWith f xs
\end{code}
A paranoid @zip@ (and some @zipWith@ friends) that checks the lists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment