[project @ 1996-04-30 17:34:02 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / Util.lhs
index 2aaec61..0ce1f49 100644 (file)
@@ -39,6 +39,7 @@ module Util (
        IF_NOT_GHC(forall COMMA exists COMMA)
        zipEqual, zipWithEqual, zipWith3Equal, zipWith4Equal,
         zipLazy,
+       mapAndUnzip,
        nOfThem, lengthExceeds, isSingleton,
        startsWith, endsWith,
 #if defined(COMPILING_GHC)
@@ -185,6 +186,18 @@ zipLazy (x:xs) ~(y:ys) = (x,y) : zipLazy xs ys
 \end{code}
 
 \begin{code}
+mapAndUnzip :: (a -> (b, c)) -> [a] -> ([b], [c])
+
+mapAndUnzip f [] = ([],[])
+mapAndUnzip f (x:xs)
+  = let
+       (r1,  r2)  = f x
+       (rs1, rs2) = mapAndUnzip f xs
+    in
+    (r1:rs1, r2:rs2)
+\end{code}
+
+\begin{code}
 nOfThem :: Int -> a -> [a]
 nOfThem n thing = take n (repeat thing)