Big tidy-up of deriving code
[ghc-hetmet.git] / compiler / utils / Util.lhs
index a7b65e8..6463c1a 100644 (file)
@@ -12,7 +12,7 @@ module Util (
         zipLazy, stretchZipWith,
        mapFst, mapSnd,
        mapAndUnzip, mapAndUnzip3,
         zipLazy, stretchZipWith,
        mapFst, mapSnd,
        mapAndUnzip, mapAndUnzip3,
-       nOfThem, filterOut, partitionWith,
+       nOfThem, filterOut, partitionWith, splitEithers,
 
        lengthExceeds, lengthIs, lengthAtLeast, 
        listLengthCmp, atLength, equalLength, compareLength,
 
        lengthExceeds, lengthIs, lengthAtLeast, 
        listLengthCmp, atLength, equalLength, compareLength,
@@ -177,6 +177,13 @@ partitionWith f (x:xs) = case f x of
                       where
                         (bs,cs) = partitionWith f xs
 
                       where
                         (bs,cs) = partitionWith f xs
 
+splitEithers :: [Either a b] -> ([a], [b])
+splitEithers [] = ([],[])
+splitEithers (e : es) = case e of
+                         Left x -> (x:xs, ys)
+                         Right y -> (xs, y:ys)
+                     where
+                       (xs,ys) = splitEithers es
 \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