on master help sign in
Remove sliceSepByMax
f6522bdHarendra Kumar
src/Streamly/Internal/Data/Fold.hs−38
@@ -145,7 +145,6 @@ module Streamly.Internal.Data.Fold
145 -- By elements
145 -- By elements
146 , sliceSepBy
146 , sliceSepBy
147 -- , breakOn
147 -- , breakOn
148− , sliceSepByMax
149 , sliceEndWith
148 , sliceEndWith
150 -- , breakAfter
149 -- , breakAfter
151 {-
150 {-
@@ -1044,43 +1043,6 @@ sliceSepBy predicate (Fold fstep finitial fextract) =
1044 then fstep s a
1043 then fstep s a
1045 else Done <$> fextract s
1044 else Done <$> fextract s
1046
1045
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−
1084-- | Collect stream elements until an element succeeds the predicate. Also take
1046-- | Collect stream elements until an element succeeds the predicate. Also take
1085-- the element on which the predicate succeeded. The succeeding element is
1047-- the element on which the predicate succeeded. The succeeding element is
1086-- treated as a suffix separator which is kept in the output segement.
1048-- 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
781 path <-
781 path <-
782 if pathLen /= 0
782 if pathLen /= 0
783 then do
783 then do
784− -- XXX sliceSepByMax drops the separator so assumes a null
784+ -- XXX sliceSepBy drops the separator so assumes a null
785 -- terminated path, we should use a takeWhile nested inside a
785 -- terminated path, we should use a takeWhile nested inside a
786 -- takeP
786 -- takeP
787 pth <-
787 pth <-
788 PR.fromFold
788 PR.fromFold
789+ $ FL.sliceSepBy (== 0)
789− $ FL.sliceSepByMax (== 0) pathLen (A.writeN pathLen)
790+ $ FL.takeLE pathLen (A.writeN pathLen)
790 let remaining = pathLen - A.length pth - 1
791 let remaining = pathLen - A.length pth - 1
791 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
792 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
792 return pth
793 return pth
test/Streamly/Test/Data/Fold.hs+1−1
@@ -236,7 +236,7 @@ sliceSepByMax =
236 forAll (chooseInt (min_value, max_value)) $ \n ->
236 forAll (chooseInt (min_value, max_value)) $ \n ->
237 forAll (listOf (chooseInt (0, 1))) $ \ls ->
237 forAll (listOf (chooseInt (0, 1))) $ \ls ->
238 let p = (== 1)
238 let p = (== 1)
239− f = F.sliceSepByMax p n FL.toList
239+ f = F.sliceSepBy p (F.takeLE n FL.toList)
240 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
240 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
241 in case S.fold f (S.fromList ls) of
241 in case S.fold f (S.fromList ls) of
242 Right xs -> checkListEqual xs ys
242 Right xs -> checkListEqual xs ys
test/Streamly/Test/Data/Parser/ParserD.hs+1−1
@@ -357,7 +357,7 @@ sliceSepByMax :: Property
357sliceSepByMax =
357sliceSepByMax =
358 forAll (chooseInt (min_value, max_value)) $ \n ->
358 forAll (chooseInt (min_value, max_value)) $ \n ->
359 forAll (listOf (chooseInt (0, 1))) $ \ls ->
359 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
361 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
361 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
362 Left _ -> property False
362 Left _ -> property False
363 where
363 where