projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
70820d6
)
Add new utility function, partitionWith
author
simonpj@microsoft.com
<unknown>
Fri, 10 Nov 2006 13:08:36 +0000
(13:08 +0000)
committer
simonpj@microsoft.com
<unknown>
Fri, 10 Nov 2006 13:08:36 +0000
(13:08 +0000)
compiler/utils/Util.lhs
patch
|
blob
|
history
diff --git
a/compiler/utils/Util.lhs
b/compiler/utils/Util.lhs
index
3eff34b
..
a7b65e8
100644
(file)
--- a/
compiler/utils/Util.lhs
+++ b/
compiler/utils/Util.lhs
@@
-12,7
+12,7
@@
module Util (
zipLazy, stretchZipWith,
mapFst, mapSnd,
mapAndUnzip, mapAndUnzip3,
zipLazy, stretchZipWith,
mapFst, mapSnd,
mapAndUnzip, mapAndUnzip3,
- nOfThem, filterOut,
+ nOfThem, filterOut, partitionWith,
lengthExceeds, lengthIs, lengthAtLeast,
listLengthCmp, atLength, equalLength, compareLength,
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
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
\end{code}
A paranoid @zip@ (and some @zipWith@ friends) that checks the lists