@@ -159,13 +159,6 @@ module Streamly.Internal.Data.Fold
159 , splitAt -- spanN
159 , splitAt -- spanN
160 -- , splitIn -- sessionN
160 -- , splitIn -- sessionN
162− -- XXX To be moved to parsers
164− , break -- breakBefore
169 -- By sequences
162 -- By sequences
170 -- , breakOnSeq
163 -- , breakOnSeq
171 -- , breakOnStream -- on a stream
164 -- , breakOnStream -- on a stream
@@ -1119,289 +1112,6 @@ sliceEndWith predicate (Fold fstep finitial fextract) =
1119 Partial s1 -> Done <$> fextract s1
1112 Partial s1 -> Done <$> fextract s1
1120 Done b -> return $ Done b
1113 Done b -> return $ Done b
1122−data SpanByState a bl fl fr
1124− | SpanByLeft !a !fl
1125− | SpanByRight !bl !fr
1127−-- | Break the input stream into two groups, the first group takes the input as
1128−-- long as the predicate applied to the first element of the stream and next
1129−-- input element holds 'True', the second group takes the rest of the input.
1133−{-# INLINE spanBy #-}
1136− => (a -> a -> Bool)
1140−spanBy cmp (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1141− Fold step initial extract
1148− Partial fl -> return $ Partial $ SpanByLeft0 fl
1153− Partial fr -> Partial $ SpanByRight bl fr
1154− Done br -> Done (bl, br)
1156− step (SpanByLeft0 fl) input = do
1157− sfl <- stepL fl input
1159− Partial fl1 -> return $ Partial $ SpanByLeft input fl1
1164− Partial fr -> Partial $ SpanByRight bl fr
1165− Done br -> Done (bl, br)
1166− step (SpanByLeft frst fl) input =
1169− sfl <- stepL fl input
1171− Partial fl1 -> return $ Partial $ SpanByLeft frst fl1
1176− Partial fr -> Partial $ SpanByRight bl fr
1177− Done br -> Done (bl, br)
1183− sfr <- stepR fr input
1186− Partial fr1 -> Partial $ SpanByRight bl fr1
1187− Done br -> Done (bl, br)
1188− Done br -> return $ Done (bl, br)
1189− step (SpanByRight bl fr) input = do
1190− sfr <- stepR fr input
1193− Partial fr1 -> Partial $ SpanByRight bl fr1
1194− Done br -> Done (bl, br)
1196− extract (SpanByLeft0 fl) = do
1200− Partial fr -> (bl, ) <$> extractR fr
1201− Done br -> return (bl, br)
1202− extract (SpanByLeft _ fl) = do
1206− Partial fr -> (bl, ) <$> extractR fr
1207− Done br -> return (bl, br)
1208− extract (SpanByRight bl fr) = (bl, ) <$> extractR fr
1210−data SpanState bl fl fr
1212− | SpanRight !bl !fr
1214−-- | @span p f1 f2@ composes folds @f1@ and @f2@ such that @f1@ consumes the
1215−-- input as long as the predicate @p@ is 'True'. @f2@ consumes the rest of the
1218−-- > let span_ p xs = S.fold (FL.span p FL.toList FL.toList) $ S.fromList xs
1220−-- >>> span_ (< 1) [1,2,3]
1223−-- >>> span_ (< 2) [1,2,3]
1226−-- >>> span_ (< 4) [1,2,3]
1231−-- This can be considered as a two-fold version of 'ltakeWhile' where we take
1232−-- both the segments instead of discarding the leftover.
1240−span p (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1241− Fold step initial extract
1248− Partial fl -> return $ Partial $ SpanLeft fl
1253− Partial fr -> Partial $ SpanRight bl fr
1254− Done br -> Done (bl, br)
1256− step (SpanLeft fl) input =
1259− sfl <- stepL fl input
1261− Partial fl1 -> return $ Partial $ SpanLeft fl1
1266− Partial fr -> Partial $ SpanRight bl fr
1267− Done br -> Done (bl, br)
1273− sfr <- stepR fr input
1276− Partial fr1 -> Partial $ SpanRight bl fr1
1277− Done br -> Done (bl, br)
1278− Done br -> return $ Done (bl, br)
1279− step (SpanRight bl fr) input = do
1280− sfr <- stepR fr input
1283− Partial fr1 -> Partial $ SpanRight bl fr1
1284− Done br -> Done (bl, br)
1286− extract (SpanLeft fl) = do
1290− Partial fr -> (bl, ) <$> extractR fr
1291− Done br -> return (bl, br)
1292− extract (SpanRight bl fr) = (bl, ) <$> extractR fr
1295−-- > break p = span (not . p)
1297−-- Break as soon as the predicate becomes 'True'. @break p f1 f2@ composes
1298−-- folds @f1@ and @f2@ such that @f1@ stops consuming input as soon as the
1299−-- predicate @p@ becomes 'True'. The rest of the input is consumed @f2@.
1301−-- This is the binary version of 'splitBy'.
1303−-- > let break_ p xs = S.fold (S.break p FL.toList FL.toList) $ S.fromList xs
1305−-- >>> break_ (< 1) [3,2,1]
1308−-- >>> break_ (< 2) [3,2,1]
1311−-- >>> break_ (< 4) [3,2,1]
1315−{-# INLINE break #-}
1322−break p = span (not . p)
1324−-- | Like 'spanBy' but applies the predicate in a rolling fashion i.e.
1325−-- predicate is applied to the previous and the next input elements.
1328−{-# INLINE spanByRolling #-}
1331− => (a -> a -> Bool)
1335−spanByRolling cmp (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1336− Fold step initial extract
1343− Partial fl -> return $ Partial $ SpanByLeft0 fl
1348− Partial fr -> Partial $ SpanByRight bl fr
1349− Done br -> Done (bl, br)
1351− step (SpanByLeft0 fl) input = do
1352− sfl <- stepL fl input
1354− Partial fl1 -> return $ Partial $ SpanByLeft input fl1
1359− Partial fr -> Partial $ SpanByRight bl fr
1360− Done br -> Done (bl, br)
1361− step (SpanByLeft input0 fl) input =
1362− if cmp input0 input
1364− sfl <- stepL fl input
1366− Partial fl1 -> return $ Partial $ SpanByLeft input fl1
1371− Partial fr -> Partial $ SpanByRight bl fr
1372− Done br -> Done (bl, br)
1378− sfr <- stepR fr input
1381− Partial fr1 -> Partial $ SpanByRight bl fr1
1382− Done br -> Done (bl, br)
1383− Done br -> return $ Done (bl, br)
1384− step (SpanByRight bl fr) input = do
1385− sfr <- stepR fr input
1388− Partial fr1 -> Partial $ SpanByRight bl fr1
1389− Done br -> Done (bl, br)
1391− extract (SpanByLeft0 fl) = do
1395− Partial fr -> (bl, ) <$> extractR fr
1396− Done br -> return (bl, br)
1397− extract (SpanByLeft _ fl) = do
1401− Partial fr -> (bl, ) <$> extractR fr
1402− Done br -> return (bl, br)
1403− extract (SpanByRight bl fr) = (bl, ) <$> extractR fr
1405------------------------------------------------------------------------------
1115------------------------------------------------------------------------------
1406-- Binary splitting on a separator
1116-- Binary splitting on a separator
1407------------------------------------------------------------------------------
1117------------------------------------------------------------------------------