@@ -282,23 +282,6 @@ module Streamly.Internal.Prelude
283 -- ** Breaking
283 -- ** Breaking
287− -- , splitIn -- sessionN
291− , break -- breakBefore
300− -- , breakOnStream -- on a stream
303 , chunksOf
286 , chunksOf
304 , chunksOf2
287 , chunksOf2
@@ -351,7 +334,7 @@ module Streamly.Internal.Prelude
351 -- , splitOnAnyPrefixSeq
334 -- , splitOnAnyPrefixSeq
353 -- -- *** Splitting By Streams
336 -- -- *** Splitting By Streams
354− -- | Splitting a stream using another stream as separator.
337+ -- -- | Splitting a stream using another stream as separator.
356 -- Nested splitting
339 -- Nested splitting
357 , splitInnerBy
340 , splitInnerBy
@@ -3122,54 +3105,6 @@ concatMapTreeYieldLeavesWith combine f = concatMapLoopWith combine f yield
3122------------------------------------------------------------------------------
3105------------------------------------------------------------------------------
3125−-- | @splitAt n f1 f2@ composes folds @f1@ and @f2@ such that first @n@
3126−-- elements of its input are consumed by fold @f1@ and the rest of the stream
3127−-- is consumed by fold @f2@.
3129−-- > let splitAt_ n xs = S.fold (FL.splitAt n FL.toList FL.toList) $ S.fromList xs
3131−-- >>> splitAt_ 6 "Hello World!"
3132−-- > ("Hello ","World!")
3134−-- >>> splitAt_ (-1) [1,2,3]
3137−-- >>> splitAt_ 0 [1,2,3]
3140−-- >>> splitAt_ 1 [1,2,3]
3143−-- >>> splitAt_ 3 [1,2,3]
3146−-- >>> splitAt_ 4 [1,2,3]
3151−-- This can be considered as a two-fold version of 'ltake' where we take both
3152−-- the segments instead of discarding the leftover.
3154−{-# INLINE splitAt #-}
3161−splitAt n (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
3162− Fold step initial extract
3164− initial = Tuple3' <$> return n <*> initialL <*> initialR
3166− step (Tuple3' i xL xR) input =
3168− then stepL xL input >>= (\a -> return (Tuple3' (i - 1) a xR))
3169− else stepR xR input >>= (\b -> return (Tuple3' i xL b))
3171− extract (Tuple3' _ a b) = (,) <$> extractL a <*> extractR b
3173------------------------------------------------------------------------------
3108------------------------------------------------------------------------------
3174-- N-ary APIs
3109-- N-ary APIs
3175------------------------------------------------------------------------------
3110------------------------------------------------------------------------------
@@ -3268,145 +3203,6 @@ intervalsOf n f xs =
3268 splitWithSuffix isNothing (FL.lcatMaybes f)
3203 splitWithSuffix isNothing (FL.lcatMaybes f)
3269 (interjectSuffix n (return Nothing) (Serial.map Just xs))
3204 (interjectSuffix n (return Nothing) (Serial.map Just xs))
3271−------------------------------------------------------------------------------
3272−-- Element Aware APIs
3273−------------------------------------------------------------------------------
3275−------------------------------------------------------------------------------
3277−------------------------------------------------------------------------------
3279−-- | Break the input stream into two groups, the first group takes the input as
3280−-- long as the predicate applied to the first element of the stream and next
3281−-- input element holds 'True', the second group takes the rest of the input.
3287− => (a -> a -> Bool)
3291−spanBy cmp (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
3292− Fold step initial extract
3295− initial = Tuple3' <$> initialL <*> initialR <*> return (Tuple' Nothing True)
3297− step (Tuple3' a b (Tuple' (Just frst) isFirstG)) input =
3298− if cmp frst input && isFirstG
3300− >>= (\a' -> return (Tuple3' a' b (Tuple' (Just frst) isFirstG)))
3302− >>= (\a' -> return (Tuple3' a a' (Tuple' Nothing False)))
3304− step (Tuple3' a b (Tuple' Nothing isFirstG)) input =
3307− >>= (\a' -> return (Tuple3' a' b (Tuple' (Just input) isFirstG)))
3309− >>= (\a' -> return (Tuple3' a a' (Tuple' Nothing False)))
3311− extract (Tuple3' a b _) = (,) <$> extractL a <*> extractR b
3313−-- | @span p f1 f2@ composes folds @f1@ and @f2@ such that @f1@ consumes the
3314−-- input as long as the predicate @p@ is 'True'. @f2@ consumes the rest of the
3317−-- > let span_ p xs = S.fold (S.span p FL.toList FL.toList) $ S.fromList xs
3319−-- >>> span_ (< 1) [1,2,3]
3322−-- >>> span_ (< 2) [1,2,3]
3325−-- >>> span_ (< 4) [1,2,3]
3330−-- This can be considered as a two-fold version of 'ltakeWhile' where we take
3331−-- both the segments instead of discarding the leftover.
3339−span p (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
3340− Fold step initial extract
3344− initial = Tuple3' <$> initialL <*> initialR <*> return True
3346− step (Tuple3' a b isFirstG) input =
3347− if isFirstG && p input
3348− then stepL a input >>= (\a' -> return (Tuple3' a' b True))
3349− else stepR b input >>= (\a' -> return (Tuple3' a a' False))
3351− extract (Tuple3' a b _) = (,) <$> extractL a <*> extractR b
3354−-- > break p = span (not . p)
3356−-- Break as soon as the predicate becomes 'True'. @break p f1 f2@ composes
3357−-- folds @f1@ and @f2@ such that @f1@ stops consuming input as soon as the
3358−-- predicate @p@ becomes 'True'. The rest of the input is consumed @f2@.
3360−-- This is the binary version of 'splitBy'.
3362−-- > let break_ p xs = S.fold (S.break p FL.toList FL.toList) $ S.fromList xs
3364−-- >>> break_ (< 1) [3,2,1]
3367−-- >>> break_ (< 2) [3,2,1]
3370−-- >>> break_ (< 4) [3,2,1]
3374−{-# INLINE break #-}
3381−break p = span (not . p)
3383−-- | Like 'spanBy' but applies the predicate in a rolling fashion i.e.
3384−-- predicate is applied to the previous and the next input elements.
3387−{-# INLINE spanByRolling #-}
3390− => (a -> a -> Bool)
3394−spanByRolling cmp (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
3395− Fold step initial extract
3398− initial = Tuple3' <$> initialL <*> initialR <*> return Nothing
3400− step (Tuple3' a b (Just frst)) input =
3402− then stepL a input >>= (\a' -> return (Tuple3' a' b (Just input)))
3403− else stepR b input >>= (\b' -> return (Tuple3' a b' (Just input)))
3405− step (Tuple3' a b Nothing) input =
3406− stepL a input >>= (\a' -> return (Tuple3' a' b (Just input)))
3408− extract (Tuple3' a b _) = (,) <$> extractL a <*> extractR b
3410------------------------------------------------------------------------------
3206------------------------------------------------------------------------------
3411-- N-ary APIs
3207-- N-ary APIs
3412------------------------------------------------------------------------------
3208------------------------------------------------------------------------------
@@ -3465,26 +3261,6 @@ groupsByRolling cmp f m = D.fromStreamD $ D.groupsRollingBy cmp f (D.toStreamD
3465groups :: (IsStream t, Monad m, Eq a) => Fold m a b -> t m a -> t m b
3261groups :: (IsStream t, Monad m, Eq a) => Fold m a b -> t m a -> t m b
3466groups = groupsBy (==)
3262groups = groupsBy (==)
3468−------------------------------------------------------------------------------
3469−-- Binary splitting on a separator
3470−------------------------------------------------------------------------------
3473−-- | Find the first occurrence of the specified sequence in the input stream
3474−-- and break the input stream into two parts, the first part consisting of the
3475−-- stream before the sequence and the second part consisting of the sequence
3476−-- and the rest of the stream.
3478−-- > let breakOn_ pat xs = S.fold (S.breakOn pat FL.toList FL.toList) $ S.fromList xs
3480−-- >>> breakOn_ "dear" "Hello dear world!"
3481−-- > ("Hello ","dear world!")
3483−{-# INLINE breakOn #-}
3484−breakOn :: Monad m => Array a -> Fold m a b -> Fold m a c -> Fold m a (b,c)
3485−breakOn pat f m = undefined
3488------------------------------------------------------------------------------
3264------------------------------------------------------------------------------
3489-- N-ary split on a predicate
3265-- N-ary split on a predicate
3490------------------------------------------------------------------------------
3266------------------------------------------------------------------------------