@@ -31,12 +31,10 @@ module Streamly.Internal.Data.Fold
3131 , foldl'
3232 , foldlM'
3333 , foldl1'
34+ , foldt'
35+ , foldtM'
3436 , foldr
3537 , foldrM
36− , mkFold
37− , mkFold_
38− , mkFoldM
39− , mkFoldM_
4038
4139 -- * Folds
4240 -- ** Identity
@@ -700,7 +698,7 @@ sum = foldl' (+) 0
700698-- /Since 0.8.0 (Added 'Eq' constraint)/
701699{-# INLINE product #-}
702700product :: (Monad m, Num a, Eq a) => Fold m a a
703−product = mkFold_ step (Partial 1)
701+product = foldt' step (Partial 1) id
704702
705703 where
706704
@@ -1005,7 +1003,7 @@ drainN n = take n drain
10051003-- /Pre-release/
10061004{-# INLINE genericIndex #-}
10071005genericIndex :: (Integral i, Monad m) => i -> Fold m a (Maybe a)
1008−genericIndex i = mkFold step (Partial 0) (const Nothing)
1006+genericIndex i = foldt' step (Partial 0) (const Nothing)
10091007
10101008 where
10111009
@@ -1029,7 +1027,7 @@ index = genericIndex
10291027--
10301028{-# INLINE maybe #-}
10311029maybe :: Monad m => (a -> Maybe b) -> Fold m a (Maybe b)
1032−maybe f = mkFold_ (const (Done . f)) (Partial Nothing)
1030+maybe f = foldt' (const (Done . f)) (Partial Nothing) id
10331031
10341032-- Naming notes:
10351033--
@@ -1079,7 +1077,7 @@ head = one
10791077-- @since 0.7.0
10801078{-# INLINE find #-}
10811079find :: Monad m => (a -> Bool) -> Fold m a (Maybe a)
1082−find predicate = mkFold step (Partial ()) (const Nothing)
1080+find predicate = foldt' step (Partial ()) (const Nothing)
10831081
10841082 where
10851083
@@ -1096,7 +1094,7 @@ find predicate = mkFold step (Partial ()) (const Nothing)
10961094-- @since 0.7.0
10971095{-# INLINE lookup #-}
10981096lookup :: (Eq a, Monad m) => a -> Fold m (a,b) (Maybe b)
1099−lookup a0 = mkFold step (Partial ()) (const Nothing)
1097+lookup a0 = foldt' step (Partial ()) (const Nothing)
11001098
11011099 where
11021100
@@ -1110,7 +1108,7 @@ lookup a0 = mkFold step (Partial ()) (const Nothing)
11101108-- @since 0.7.0
11111109{-# INLINE findIndex #-}
11121110findIndex :: Monad m => (a -> Bool) -> Fold m a (Maybe Int)
1113−findIndex predicate = mkFold step (Partial 0) (const Nothing)
1111+findIndex predicate = foldt' step (Partial 0) (const Nothing)
11141112
11151113 where
11161114
@@ -1156,7 +1154,7 @@ elemIndex a = findIndex (a ==)
11561154-- @since 0.7.0
11571155{-# INLINE null #-}
11581156null :: Monad m => Fold m a Bool
1159−null = mkFold (\() _ -> Done False) (Partial ()) (const True)
1157+null = foldt' (\() _ -> Done False) (Partial ()) (const True)
11601158
11611159-- | Returns 'True' if any of the elements of a stream satisfies a predicate.
11621160--
@@ -1168,7 +1166,7 @@ null = mkFold (\() _ -> Done False) (Partial ()) (const True)
11681166-- @since 0.7.0
11691167{-# INLINE any #-}
11701168any :: Monad m => (a -> Bool) -> Fold m a Bool
1171−any predicate = mkFold_ step initial
1169+any predicate = foldt' step initial id
11721170
11731171 where
11741172
@@ -1198,7 +1196,7 @@ elem a = any (a ==)
11981196-- @since 0.7.0
11991197{-# INLINE all #-}
12001198all :: Monad m => (a -> Bool) -> Fold m a Bool
1201−all predicate = mkFold_ step initial
1199+all predicate = foldt' step initial id
12021200
12031201 where
12041202