@@ -74,16 +74,17 @@ module Streamly.Streams.StreamK
74 -- * Elimination
74 -- * Elimination
75 -- ** General Folds
75 -- ** General Folds
85− , foldx'
86+ , foldlx'
86− , foldxM'
87+ , foldlMx'
88 -- ** Specialized Folds
89 -- ** Specialized Folds
89 , runStream
90 , runStream
@@ -410,10 +411,10 @@ foldr1 step m = do
410-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
411-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
412-- Note that the accumulator is always evaluated including the initial value.
413-- Note that the accumulator is always evaluated including the initial value.
413−{-# INLINE foldx' #-}
414+{-# INLINE foldlx' #-}
414−foldx' :: forall t m a b x. (IsStream t, Monad m)
415+foldlx' :: forall t m a b x. (IsStream t, Monad m)
415 => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
416 => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
416−foldx' step begin done m = get $ go m begin
417+foldlx' step begin done m = get $ go m begin
418 {-# NOINLINE get #-}
419 {-# NOINLINE get #-}
419 get :: t m x -> m b
420 get :: t m x -> m b
@@ -440,14 +441,14 @@ foldx' step begin done m = get $ go m begin
440-- | Strict left associative fold.
441-- | Strict left associative fold.
441{-# INLINE foldl' #-}
442{-# INLINE foldl' #-}
442foldl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
443foldl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
443−foldl' step begin = foldx' step begin id
444+foldl' step begin = foldlx' step begin id
445-- XXX replace the recursive "go" with explicit continuations.
446-- XXX replace the recursive "go" with explicit continuations.
446-- | Like 'foldx', but with a monadic step function.
447-- | Like 'foldx', but with a monadic step function.
447−{-# INLINABLE foldxM' #-}
448+{-# INLINABLE foldlMx' #-}
448−foldxM' :: (IsStream t, Monad m)
449+foldlMx' :: (IsStream t, Monad m)
449 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
450 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
450−foldxM' step begin done m = go begin m
451+foldlMx' step begin done m = go begin m
452 go !acc m1 =
453 go !acc m1 =
453 let stop = acc >>= done
454 let stop = acc >>= done
@@ -458,7 +459,7 @@ foldxM' step begin done m = go begin m
458-- | Like 'foldl'' but with a monadic step function.
459-- | Like 'foldl'' but with a monadic step function.
459{-# INLINE foldlM' #-}
460{-# INLINE foldlM' #-}
460foldlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> m b
461foldlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> m b
461−foldlM' step begin = foldxM' step (return begin) return
462+foldlM' step begin = foldlMx' step (return begin) return
463-- | Lazy left fold to a stream.
464-- | Lazy left fold to a stream.
464{-# INLINE foldlS #-}
465{-# INLINE foldlS #-}
@@ -584,7 +585,7 @@ any p m = go m
584-- | Extract the last element of the stream, if any.
585-- | Extract the last element of the stream, if any.
585{-# INLINE last #-}
586{-# INLINE last #-}
586last :: (IsStream t, Monad m) => t m a -> m (Maybe a)
587last :: (IsStream t, Monad m) => t m a -> m (Maybe a)
587−last = foldx' (\_ y -> Just y) Nothing id
588+last = foldlx' (\_ y -> Just y) Nothing id
589{-# INLINE minimum #-}
590{-# INLINE minimum #-}
590minimum :: (IsStream t, Monad m, Ord a) => t m a -> m (Maybe a)
591minimum :: (IsStream t, Monad m, Ord a) => t m a -> m (Maybe a)