@@ -43,6 +43,8 @@ module Streamy.Streaming (
43
43
, Streamy.Streaming. intercalates
44
44
, Streamy.Streaming. yields
45
45
, Streamy.Streaming. takes
46
+ , Streamy.Streaming. folds
47
+ , Streamy.Streaming. foldsM
46
48
, Streamy.Streaming. splitAt
47
49
, Streamy.Streaming. span
48
50
) where
@@ -82,7 +84,7 @@ each :: (Monad m, Foldable f) => f a -> Stream a m ()
82
84
each x = Stream (Q. each x)
83
85
84
86
toList :: Monad m => Stream a m r -> m ([a ],r )
85
- toList (Stream s) = toTup <$> Q. toList s
87
+ toList (Stream s) = Q. lazily <$> Q. toList s
86
88
87
89
toList_ :: Monad m => Stream a m () -> m [a ]
88
90
toList_ (Stream s) = Q. toList_ s
@@ -145,13 +147,13 @@ any_ :: Monad m => (a -> Bool) -> Stream a m () -> m Bool
145
147
any_ f (Stream s) = Q. any_ f s
146
148
147
149
fold :: Monad m => (x -> a -> x ) -> x -> (x -> b ) -> Stream a m r -> m (b ,r )
148
- fold step begin done (Stream s) = toTup <$> Q. fold step begin done s
150
+ fold step begin done (Stream s) = Q. lazily <$> Q. fold step begin done s
149
151
150
152
fold_ :: Monad m => (x -> a -> x ) -> x -> (x -> b ) -> Stream a m () -> m b
151
153
fold_ step begin done (Stream s) = Q. fold_ step begin done s
152
154
153
155
foldM :: Monad m => (x -> a -> m x ) -> m x -> (x -> m b ) -> Stream a m r -> m (b ,r )
154
- foldM step begin done (Stream s) = toTup <$> Q. foldM step begin done s
156
+ foldM step begin done (Stream s) = Q. lazily <$> Q. foldM step begin done s
155
157
156
158
foldM_ :: Monad m => (x -> a -> m x ) -> m x -> (x -> m b ) -> Stream a m () -> m b
157
159
foldM_ step begin done (Stream s) = Q. foldM_ step begin done s
@@ -186,13 +188,19 @@ yields (Stream s) = Groups $ Q.yields s
186
188
takes :: Monad m => Int -> Groups a m () -> Groups a m ()
187
189
takes i (Groups gs) = Groups $ Q. takes i gs
188
190
191
+ folds :: Monad m => (x -> a -> x ) -> x -> (x -> b ) -> Groups a m r -> Stream b m r
192
+ folds step begin done (Groups gs) =
193
+ -- https://stackoverflow.com/questions/45773251/how-to-implement-folds-and-foldsm-from-pipes-group-for-the-streaming-package
194
+ Stream $ Q. mapped (Q. fold step begin done) gs
195
+
196
+ foldsM :: Monad m => (x -> a -> m x ) -> m x -> (x -> m b ) -> Groups a m r -> Stream b m r
197
+ foldsM step begin done (Groups gs) =
198
+ -- https://stackoverflow.com/questions/45773251/how-to-implement-folds-and-foldsm-from-pipes-group-for-the-streaming-package
199
+ Stream $ Q. mapped (Q. foldM step begin done) gs
200
+
189
201
splitAt :: Monad m => Int -> Stream a m r -> Stream a m (Stream a m r )
190
202
splitAt i (Stream s) = Stream <$> Stream (Q. splitAt i s)
191
203
192
204
span :: Monad m => (a -> Bool ) -> Stream a m r -> Stream a m (Stream a m r )
193
205
span f (Stream s) = Stream <$> Stream (Q. span f s)
194
206
195
- --
196
- toTup :: Of a r -> (a ,r )
197
- toTup = \ (a :> r) -> (a,r)
198
-
0 commit comments