summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Stream.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/utils/Stream.hs b/compiler/utils/Stream.hs
index ad01fad40c..2ad2b8cc7a 100644
--- a/compiler/utils/Stream.hs
+++ b/compiler/utils/Stream.hs
@@ -7,7 +7,7 @@
-- -----------------------------------------------------------------------------
module Stream (
Stream(..), yield, liftIO,
- collect, fromList,
+ collect, consume, fromList,
Stream.map, Stream.mapM, Stream.mapAccumL
) where
@@ -71,6 +71,15 @@ collect str = go str []
Left () -> return (reverse acc)
Right (a, str') -> go str' (a:acc)
+consume :: Monad m => Stream m a b -> (a -> m ()) -> m b
+consume str f = do
+ r <- runStream str
+ case r of
+ Left ret -> return ret
+ Right (a, str') -> do
+ f a
+ consume str' f
+
-- | Turn a list into a 'Stream', by yielding each element in turn.
fromList :: Monad m => [a] -> Stream m a ()
fromList = mapM_ yield