on master help sign in
Remove sliceSepByMax

It can be expressed as: sliceSepByMax p n = sliceSepBy p . takeLE n

commitf6522bdd179fceb5ee1bb68e40a7801827e30224 authorHarendra Kumar <harendra@composewell.com> dateSun 7 Feb 2021, 20:23 (6 years ago) parentcdccb78
4 files changed+5−42
src/Streamly/Internal/Data/Fold.hs−38 src/Streamly/Internal/FileSystem/Event/Linux.hs+3−2 test/Streamly/Test/Data/Fold.hs+1−1 test/Streamly/Test/Data/Parser/ParserD.hs+1−1
src/Streamly/Internal/Data/Fold.hs−38
@@ -145,7 +145,6 @@ module Streamly.Internal.Data.Fold
145145 -- By elements
146146 , sliceSepBy
147147 -- , breakOn
148− , sliceSepByMax
149148 , sliceEndWith
150149 -- , breakAfter
151150 {-
@@ -1044,43 +1043,6 @@ sliceSepBy predicate (Fold fstep finitial fextract) =
10441043 then fstep s a
10451044 else Done <$> fextract s
10461045
1047−-- | Like 'sliceSepBy' but terminates a parse even before the separator
1048−-- is encountered if its size exceeds the specified maximum limit.
1049−--
1050−-- > take n = PR.sliceSepByMax (const True) n
1051−-- > sliceSepBy p = PR.sliceSepByMax p maxBound
1052−--
1053−-- Let's use the following definitions for illustration:
1054−--
1055−-- > splitOn p n = PR.many FL.toList $ PR.sliceSepByMax p n (FL.toList)
1056−-- > splitOn' p n = S.parse (splitOn p n) . S.fromList
1057−--
1058−-- >>> splitOn' (== '.') 0 ""
1059−-- [""]
1060−--
1061−-- >>> splitOn' (== '.') 0 "a"
1062−-- infinite list of empty strings
1063−--
1064−-- >>> splitOn' (== '.') 3 "hello.world"
1065−-- ["hel","lo","wor","ld"]
1066−--
1067−-- If the separator is found and the limit is reached at the same time then it
1068−-- behaves just like 'sliceSepBy' i.e. the separator is dropped.
1069−--
1070−-- >>> splitOn' (== '.') 0 "."
1071−-- ["",""]
1072−--
1073−-- >>> splitOn' (== '.') 0 ".."
1074−-- ["","",""]
1075−--
1076−-- Stops - when the predicate succeeds or the limit is reached.
1077−--
1078−-- /Internal/
1079−{-# INLINABLE sliceSepByMax #-}
1080−sliceSepByMax :: Monad m
1081− => (a -> Bool) -> Int -> Fold m a b -> Fold m a b
1082−sliceSepByMax p n = sliceSepBy p . takeLE n
1083−
10841046-- | Collect stream elements until an element succeeds the predicate. Also take
10851047-- the element on which the predicate succeeded. The succeeding element is
10861048-- treated as a suffix separator which is kept in the output segement.
src/Streamly/Internal/FileSystem/Event/Linux.hs+3−2
@@ -781,12 +781,13 @@ readOneEvent cfg wt@(Watch _ wdMap) = do
781781 path <-
782782 if pathLen /= 0
783783 then do
784− -- XXX sliceSepByMax drops the separator so assumes a null
784+ -- XXX sliceSepBy drops the separator so assumes a null
785785 -- terminated path, we should use a takeWhile nested inside a
786786 -- takeP
787787 pth <-
788788 PR.fromFold
789− $ FL.sliceSepByMax (== 0) pathLen (A.writeN pathLen)
789+ $ FL.sliceSepBy (== 0)
790+ $ FL.takeLE pathLen (A.writeN pathLen)
790791 let remaining = pathLen - A.length pth - 1
791792 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
792793 return pth
test/Streamly/Test/Data/Fold.hs+1−1
@@ -236,7 +236,7 @@ sliceSepByMax =
236236 forAll (chooseInt (min_value, max_value)) $ \n ->
237237 forAll (listOf (chooseInt (0, 1))) $ \ls ->
238238 let p = (== 1)
239− f = F.sliceSepByMax p n FL.toList
239+ f = F.sliceSepBy p (F.takeLE n FL.toList)
240240 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
241241 in case S.fold f (S.fromList ls) of
242242 Right xs -> checkListEqual xs ys
test/Streamly/Test/Data/Parser/ParserD.hs+1−1
@@ -357,7 +357,7 @@ sliceSepByMax :: Property
357357sliceSepByMax =
358358 forAll (chooseInt (min_value, max_value)) $ \n ->
359359 forAll (listOf (chooseInt (0, 1))) $ \ls ->
360− case S.parseD (P.fromFold $ FL.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
360+ case S.parseD (P.fromFold $ FL.sliceSepBy predicate (FL.takeLE n FL.toList)) (S.fromList ls) of
361361 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
362362 Left _ -> property False
363363 where