@@ -30,8 +30,6 @@ module Streamly.Internal.Data.Fold.Combinators
3030 -- *** Reducers
3131 , drainMapM
3232 , the
33− , length
34− , lengthGeneric
3533 , mean
3634 , rollingHash
3735 , defaultSalt
@@ -166,8 +164,6 @@ module Streamly.Internal.Data.Fold.Combinators
166164 -- ** Trimming
167165
168166 -- By elements
169− , takeEndBy
170− , takeEndBy_
171167 , takeEndBySeq
172168 , takeEndBySeq_
173169 {-
@@ -709,30 +705,6 @@ the = foldt' step initial id
709705-- To Summary
710706------------------------------------------------------------------------------
711707
712−-- | Like 'length', except with a more general 'Num' return value
713−--
714−-- Definition:
715−--
716−-- >>> lengthGeneric = fmap getSum $ Fold.foldMap (Sum . const 1)
717−-- >>> lengthGeneric = Fold.foldl' (\n _ -> n + 1) 0
718−--
719−-- /Pre-release/
720−{-# INLINE lengthGeneric #-}
721−lengthGeneric :: (Monad m, Num b) => Fold m a b
722−lengthGeneric = foldl' (\n _ -> n + 1) 0
723−
724−-- | Determine the length of the input stream.
725−--
726−-- Definition:
727−--
728−-- >>> length = Fold.lengthGeneric
729−-- >>> length = fmap getSum $ Fold.foldMap (Sum . const 1)
730−--
731−{-# INLINE length #-}
732−length :: Monad m => Fold m a Int
733−length = lengthGeneric
734−
735−
736708-- | Determine the sum of all elements of a stream of numbers. Returns additive
737709-- identity (@0@) when the stream is empty. Note that this is not numerically
738710-- stable for floating point numbers.
@@ -1510,70 +1482,6 @@ droppingWhileM p = Fold step initial extract extract
15101482droppingWhile :: Monad m => (a -> Bool) -> Fold m a (Maybe a)
15111483droppingWhile p = droppingWhileM (return . p)
15121484
1513−-- Note: Keep this consistent with S.splitOn. In fact we should eliminate
1514−-- S.splitOn in favor of the fold.
1515−--
1516−-- XXX Use Fold.many instead once it is fixed.
1517−-- > Stream.splitOnSuffix p f = Stream.foldMany (Fold.takeEndBy_ p f)
1518−
1519−-- | Like 'takeEndBy' but drops the element on which the predicate succeeds.
1520−--
1521−-- Example:
1522−--
1523−-- >>> input = Stream.fromList "hello\nthere\n"
1524−-- >>> line = Fold.takeEndBy_ (== '\n') Fold.toList
1525−-- >>> Stream.fold line input
1526−-- "hello"
1527−--
1528−-- >>> Stream.fold Fold.toList $ Stream.foldMany line input
1529−-- ["hello","there"]
1530−--
1531−{-# INLINE takeEndBy_ #-}
1532−takeEndBy_ :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
1533−-- takeEndBy_ predicate = scanMaybe (takingEndBy_ predicate)
1534−takeEndBy_ predicate (Fold fstep finitial fextract ffinal) =
1535− Fold step finitial fextract ffinal
1536−
1537− where
1538−
1539− step s a =
1540− if not (predicate a)
1541− then fstep s a
1542− else Done <$> ffinal s
1543−
1544−-- Note:
1545−-- > Stream.splitWithSuffix p f = Stream.foldMany (Fold.takeEndBy p f)
1546−
1547−-- | Take the input, stop when the predicate succeeds taking the succeeding
1548−-- element as well.
1549−--
1550−-- Example:
1551−--
1552−-- >>> input = Stream.fromList "hello\nthere\n"
1553−-- >>> line = Fold.takeEndBy (== '\n') Fold.toList
1554−-- >>> Stream.fold line input
1555−-- "hello\n"
1556−--
1557−-- >>> Stream.fold Fold.toList $ Stream.foldMany line input
1558−-- ["hello\n","there\n"]
1559−--
1560−{-# INLINE takeEndBy #-}
1561−takeEndBy :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
1562−-- takeEndBy predicate = scanMaybe (takingEndBy predicate)
1563−takeEndBy predicate (Fold fstep finitial fextract ffinal) =
1564− Fold step finitial fextract ffinal
1565−
1566− where
1567−
1568− step s a = do
1569− res <- fstep s a
1570− if not (predicate a)
1571− then return res
1572− else do
1573− case res of
1574− Partial s1 -> Done <$> ffinal s1
1575− Done b -> return $ Done b
1576−
15771485------------------------------------------------------------------------------
15781486-- Binary splitting on a separator
15791487------------------------------------------------------------------------------