@@ -174,7 +174,7 @@ fromHandle h = fromStream go
174-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
174-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
175-- [1,2,3]
175-- [1,2,3]
177−foldr :: (IsStream t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
177+foldr :: Monad m => (a -> b -> b) -> b -> SerialT m a -> m b
178foldr step acc m = go (toStream m)
178foldr step acc m = go (toStream m)
@@ -191,7 +191,7 @@ foldr step acc m = go (toStream m)
191-- [1,2,3]
191-- [1,2,3]
193{-# INLINE foldrM #-}
193{-# INLINE foldrM #-}
194−foldrM :: (IsStream t, Monad m) => (a -> b -> m b) -> b -> t m a -> m b
194+foldrM :: Monad m => (a -> b -> m b) -> b -> SerialT m a -> m b
195foldrM step acc m = go (toStream m)
195foldrM step acc m = go (toStream m)
@@ -233,8 +233,7 @@ scanl' step begin m = scanx step begin id m
233-- argument) to the folded value at the end. This is designed to work with the
233-- argument) to the folded value at the end. This is designed to work with the
234-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
234-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
235{-# INLINE foldx #-}
235{-# INLINE foldx #-}
236−foldx :: (IsStream t, Monad m)
237− => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
236+foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> SerialT m a -> m b
238foldx step begin done m = get $ go (toStream m) begin
237foldx step begin done m = get $ go (toStream m) begin
240 {-# NOINLINE get #-}
239 {-# NOINLINE get #-}
@@ -257,19 +256,17 @@ foldx step begin done m = get $ go (toStream m) begin
257 in (S.runStream m1) Nothing stop yield
256 in (S.runStream m1) Nothing stop yield
259{-# DEPRECATED foldl "Please use foldx instead." #-}
258{-# DEPRECATED foldl "Please use foldx instead." #-}
260−foldl :: (IsStream t, Monad m)
261− => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
259+foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> SerialT m a -> m b
262foldl = foldx
260foldl = foldx
264-- | Strict left associative fold.
262-- | Strict left associative fold.
265{-# INLINE foldl' #-}
263{-# INLINE foldl' #-}
266−foldl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
264+foldl' :: Monad m => (b -> a -> b) -> b -> SerialT m a -> m b
267foldl' step begin m = foldx step begin id m
265foldl' step begin m = foldx step begin id m
269-- XXX replace the recursive "go" with explicit continuations.
267-- XXX replace the recursive "go" with explicit continuations.
270-- | Like 'foldx', but with a monadic step function.
268-- | Like 'foldx', but with a monadic step function.
271−foldxM :: (IsStream t, Monad m)
272− => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
269+foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> SerialT m a -> m b
273foldxM step begin done m = go begin (toStream m)
270foldxM step begin done m = go begin (toStream m)
275 go !acc m1 =
272 go !acc m1 =
@@ -279,18 +276,17 @@ foldxM step begin done m = go begin (toStream m)
279 in (S.runStream m1) Nothing stop yield
276 in (S.runStream m1) Nothing stop yield
281{-# DEPRECATED foldlM "Please use foldxM instead." #-}
278{-# DEPRECATED foldlM "Please use foldxM instead." #-}
282−foldlM :: (IsStream t, Monad m)
283− => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
279+foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> SerialT m a -> m b
284foldlM = foldxM
280foldlM = foldxM
286-- | Like 'foldl'' but with a monadic step function.
282-- | Like 'foldl'' but with a monadic step function.
287−foldlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> m b
283+foldlM' :: Monad m => (b -> a -> m b) -> b -> SerialT m a -> m b
288foldlM' step begin m = foldxM step (return begin) return m
284foldlM' step begin m = foldxM step (return begin) return m
290-- | Decompose a stream into its head and tail. If the stream is empty, returns
286-- | Decompose a stream into its head and tail. If the stream is empty, returns
291-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
287-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
292-- the head of the stream and 'ma' its tail.
288-- the head of the stream and 'ma' its tail.
293−uncons :: (IsStream t, Monad m) => t m a -> m (Maybe (a, t m a))
289+uncons :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (a, t m a))
294uncons m =
290uncons m =
295 let stop = return Nothing
291 let stop = return Nothing
296 yield a Nothing = return (Just (a, nil))
292 yield a Nothing = return (Just (a, nil))
@@ -298,7 +294,7 @@ uncons m =
298 in (S.runStream (toStream m)) Nothing stop yield
294 in (S.runStream (toStream m)) Nothing stop yield
300-- | Write a stream of Strings to an IO Handle.
296-- | Write a stream of Strings to an IO Handle.
301−toHandle :: (IsStream t, MonadIO m) => IO.Handle -> t m String -> m ()
297+toHandle :: MonadIO m => IO.Handle -> SerialT m String -> m ()
302toHandle h m = go (toStream m)
298toHandle h m = go (toStream m)
@@ -376,7 +372,7 @@ dropWhile p m = fromStream $ go (toStream m)
376 in (S.runStream m1) ctx stp yield
372 in (S.runStream m1) ctx stp yield
378-- | Determine whether all elements of a stream satisfy a predicate.
374-- | Determine whether all elements of a stream satisfy a predicate.
379−all :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
375+all :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
380all p m = go (toStream m)
376all p m = go (toStream m)
@@ -387,7 +383,7 @@ all p m = go (toStream m)
387 in (S.runStream m1) Nothing (return True) yield
383 in (S.runStream m1) Nothing (return True) yield
389-- | Determine whether any of the elements of a stream satisfy a predicate.
385-- | Determine whether any of the elements of a stream satisfy a predicate.
390−any :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
386+any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
391any p m = go (toStream m)
387any p m = go (toStream m)
@@ -398,22 +394,22 @@ any p m = go (toStream m)
398 in (S.runStream m1) Nothing (return False) yield
394 in (S.runStream m1) Nothing (return False) yield
400-- | Determine the sum of all elements of a stream of numbers
396-- | Determine the sum of all elements of a stream of numbers
401−sum :: (IsStream t, Monad m, Num a) => t m a -> m a
397+sum :: (Monad m, Num a) => SerialT m a -> m a
402sum = foldl (+) 0 id
398sum = foldl (+) 0 id
404-- | Determine the product of all elements of a stream of numbers
400-- | Determine the product of all elements of a stream of numbers
405−product :: (IsStream t, Monad m, Num a) => t m a -> m a
401+product :: (Monad m, Num a) => SerialT m a -> m a
406product = foldl (*) 1 id
402product = foldl (*) 1 id
408-- | Extract the first element of the stream, if any.
404-- | Extract the first element of the stream, if any.
409−head :: (IsStream t, Monad m) => t m a -> m (Maybe a)
405+head :: Monad m => SerialT m a -> m (Maybe a)
411 let stop = return Nothing
407 let stop = return Nothing
412 yield a _ = return (Just a)
408 yield a _ = return (Just a)
413 in (S.runStream (toStream m)) Nothing stop yield
409 in (S.runStream (toStream m)) Nothing stop yield
415-- | Extract all but the first element of the stream, if any.
411-- | Extract all but the first element of the stream, if any.
416−tail :: (IsStream t, Monad m) => t m a -> m (Maybe (t m a))
412+tail :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
418 let stop = return Nothing
414 let stop = return Nothing
419 yield _ Nothing = return $ Just nil
415 yield _ Nothing = return $ Just nil
@@ -422,18 +418,18 @@ tail m =
423-- | Extract the last element of the stream, if any.
419-- | Extract the last element of the stream, if any.
424{-# INLINE last #-}
420{-# INLINE last #-}
425−last :: (IsStream t, Monad m) => t m a -> m (Maybe a)
421+last :: Monad m => SerialT m a -> m (Maybe a)
426last = foldl (\_ y -> Just y) Nothing id
422last = foldl (\_ y -> Just y) Nothing id
428-- | Determine whether the stream is empty.
424-- | Determine whether the stream is empty.
429−null :: (IsStream t, Monad m) => t m a -> m Bool
425+null :: Monad m => SerialT m a -> m Bool
431 let stop = return True
427 let stop = return True
432 yield _ _ = return False
428 yield _ _ = return False
433 in (S.runStream (toStream m)) Nothing stop yield
429 in (S.runStream (toStream m)) Nothing stop yield
435-- | Determine whether an element is present in the stream.
431-- | Determine whether an element is present in the stream.
436−elem :: (IsStream t, Monad m, Eq a) => a -> t m a -> m Bool
432+elem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
437elem e m = go (toStream m)
433elem e m = go (toStream m)
@@ -443,7 +439,7 @@ elem e m = go (toStream m)
443 in (S.runStream m1) Nothing stop yield
439 in (S.runStream m1) Nothing stop yield
445-- | Determine whether an element is not present in the stream.
441-- | Determine whether an element is not present in the stream.
446−notElem :: (IsStream t, Monad m, Eq a) => a -> t m a -> m Bool
442+notElem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
447notElem e m = go (toStream m)
443notElem e m = go (toStream m)
@@ -453,7 +449,7 @@ notElem e m = go (toStream m)
453 in (S.runStream m1) Nothing stop yield
449 in (S.runStream m1) Nothing stop yield
455-- | Determine the length of the stream.
451-- | Determine the length of the stream.
456−length :: (IsStream t, Monad m) => t m a -> m Int
452+length :: Monad m => SerialT m a -> m Int
457length = foldl (\n _ -> n + 1) 0 id
453length = foldl (\n _ -> n + 1) 0 id
459-- | Returns the elements of the stream in reverse order.
455-- | Returns the elements of the stream in reverse order.
@@ -471,7 +467,7 @@ reverse m = fromStream $ go Nothing (toStream m)
472-- XXX replace the recursive "go" with continuation
468-- XXX replace the recursive "go" with continuation
473-- | Determine the minimum element in a stream.
469-- | Determine the minimum element in a stream.
474−minimum :: (IsStream t, Monad m, Ord a) => t m a -> m (Maybe a)
470+minimum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
475minimum m = go Nothing (toStream m)
471minimum m = go Nothing (toStream m)
477 go r m1 =
473 go r m1 =
@@ -486,7 +482,7 @@ minimum m = go Nothing (toStream m)
487-- XXX replace the recursive "go" with continuation
483-- XXX replace the recursive "go" with continuation
488-- | Determine the maximum element in a stream.
484-- | Determine the maximum element in a stream.
489−maximum :: (IsStream t, Monad m, Ord a) => t m a -> m (Maybe a)
485+maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
490maximum m = go Nothing (toStream m)
486maximum m = go Nothing (toStream m)
492 go r m1 =
488 go r m1 =
@@ -519,7 +515,7 @@ mapM f m = fromStream $ go (toStream m)
520-- | Apply a monadic action to each element of the stream and discard the
516-- | Apply a monadic action to each element of the stream and discard the
521-- output of the action.
517-- output of the action.
522−mapM_ :: (IsStream t, Monad m) => (a -> m b) -> t m a -> m ()
518+mapM_ :: Monad m => (a -> m b) -> SerialT m a -> m ()
523mapM_ f m = go (toStream m)
519mapM_ f m = go (toStream m)