on master help sign in
Rename Fold.ltake to Fold.takeLE
commit084cdea6016af7d9bb8f1632caedca4992f50c8b authorAdithya Kumar <adithya@composewell.com> dateFri 15 Jan 2021, 15:22 (6 years ago) parentbdedb69
12 files changed+54−54
benchmark/Streamly/Benchmark/Data/Fold.hs+6−6 benchmark/Streamly/Benchmark/Data/Parser.hs+2−2 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+2−2 benchmark/Streamly/Benchmark/Prelude/Serial/Transformation2.hs+2−2 src/Streamly/Data/Fold.hs+1−1 src/Streamly/Internal/Data/Fold.hs+7−7 src/Streamly/Internal/Data/Fold/Types.hs+8−8 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1 src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+5−5 test/Streamly/Test/Data/Fold.hs+4−4 test/Streamly/Test/Data/Parser.hs+6−6 test/Streamly/Test/Data/Parser/ParserD.hs+10−10
benchmark/Streamly/Benchmark/Data/Fold.hs+6−6
@@ -64,9 +64,9 @@ any value = IP.fold (FL.any (> value))
6464all :: (Monad m, Ord a) => a -> SerialT m a -> m Bool
6565all value = IP.fold (FL.all (<= value))
6666
67−{-# INLINE take #-}
68−take :: Monad m => Int -> SerialT m a -> m ()
69−take value = IP.fold (FL.ltake value FL.drain)
67+{-# INLINE takeLE #-}
68+takeLE :: Monad m => Int -> SerialT m a -> m ()
69+takeLE value = IP.fold (FL.takeLE value FL.drain)
7070
7171-------------------------------------------------------------------------------
7272-- Splitting by serial application
@@ -78,7 +78,7 @@ sliceSepBy value = IP.fold (FL.sliceSepBy (>= value) FL.drain)
7878
7979{-# INLINE many #-}
8080many :: Monad m => SerialT m Int -> m ()
81−many = IP.fold (FL.many FL.drain (FL.ltake 1 FL.drain))
81+many = IP.fold (FL.many FL.drain (FL.takeLE 1 FL.drain))
8282
8383{-# INLINE splitAllAny #-}
8484splitAllAny :: Monad m => Int -> SerialT m Int -> m (Bool, Bool)
@@ -229,7 +229,7 @@ o_1_space_serial_elimination value =
229229 , benchIOSink value "notElem" (S.fold (FL.notElem (value + 1)))
230230 , benchIOSink value "all" $ all value
231231 , benchIOSink value "any" $ any value
232− , benchIOSink value "take" $ take value
232+ , benchIOSink value "takeLE" $ takeLE value
233233 , benchIOSink value "sliceSepBy" $ sliceSepBy value
234234 , benchIOSink value "and" (S.fold FL.and . S.map (<= (value + 1)))
235235 , benchIOSink value "or" (S.fold FL.or . S.map (> (value + 1)))
@@ -265,7 +265,7 @@ o_1_space_serial_composition value =
265265 [ benchIOSink value "splitWith (all, any)" $ splitAllAny value
266266 , benchIOSink value "teeApplicative (all, any)"
267267 $ teeApplicative value
268− , benchIOSink value "many drain (take 1)" many
268+ , benchIOSink value "many drain (takeLE 1)" many
269269 , benchIOSink value "tee (sum, length)" teeSumLength
270270 , benchIOSink value "distribute [sum, length]" distribute
271271 , benchIOSink value "partition (sum, length)" partition
benchmark/Streamly/Benchmark/Data/Parser.hs+2−2
@@ -256,7 +256,7 @@ parseMany :: MonadCatch m => SerialT m Int -> m ()
256256parseMany =
257257 S.drain
258258 . S.map getSum
259− . IP.parseMany (PR.fromFold $ FL.ltake 2 FL.mconcat)
259+ . IP.parseMany (PR.fromFold $ FL.takeLE 2 FL.mconcat)
260260 . S.map Sum
261261
262262{-# INLINE parseIterate #-}
@@ -264,7 +264,7 @@ parseIterate :: MonadCatch m => SerialT m Int -> m ()
264264parseIterate =
265265 S.drain
266266 . S.map getSum
267− . IP.parseIterate (PR.fromFold . FL.ltake 2 . FL.sconcat) (Sum 0)
267+ . IP.parseIterate (PR.fromFold . FL.takeLE 2 . FL.sconcat) (Sum 0)
268268 . S.map Sum
269269
270270-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+2−2
@@ -311,12 +311,12 @@ chunksOfSum n inh = S.length $ S.chunksOf n FL.sum (S.unfold FH.read inh)
311311
312312foldManyChunksOfSum :: Int -> Handle -> IO Int
313313foldManyChunksOfSum n inh =
314− S.length $ IP.foldMany (FL.ltake n FL.sum) (S.unfold FH.read inh)
314+ S.length $ IP.foldMany (FL.takeLE n FL.sum) (S.unfold FH.read inh)
315315
316316parseManyChunksOfSum :: Int -> Handle -> IO Int
317317parseManyChunksOfSum n inh =
318318 S.length
319− $ IP.parseMany (PR.fromFold $ FL.ltake n FL.sum) (S.unfold FH.read inh)
319+ $ IP.parseMany (PR.fromFold $ FL.takeLE n FL.sum) (S.unfold FH.read inh)
320320
321321-- XXX investigate why we need an INLINE in this case (GHC)
322322-- Even though allocations remain the same in both cases inlining improves time
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation2.hs+2−2
@@ -137,7 +137,7 @@ foldMany :: Monad m => SerialT m Int -> m ()
137137foldMany =
138138 S.drain
139139 . S.map getSum
140− . Internal.foldMany (FL.ltake 2 FL.mconcat)
140+ . Internal.foldMany (FL.takeLE 2 FL.mconcat)
141141 . S.map Sum
142142
143143{-# INLINE _foldIterate #-}
@@ -145,7 +145,7 @@ _foldIterate :: Monad m => SerialT m Int -> m ()
145145_foldIterate =
146146 S.drain
147147 . S.map getSum
148− . Internal.foldIterate (FL.ltake 2 . FL.sconcat) (Sum 0)
148+ . Internal.foldIterate (FL.takeLE 2 . FL.sconcat) (Sum 0)
149149 . S.map Sum
150150
151151o_1_space_grouping :: Int -> [Benchmark]
src/Streamly/Data/Fold.hs+1−1
@@ -173,7 +173,7 @@ module Streamly.Data.Fold
173173
174174 {-
175175 -- ** Trimming
176− , ltake
176+ , takeLE
177177 -- takeByTime
178178 , ldrop
179179 , ldropWhile
src/Streamly/Internal/Data/Fold.hs+7−7
@@ -137,7 +137,7 @@ module Streamly.Internal.Data.Fold
137137 -}
138138
139139 -- ** Trimming
140− , ltake
140+ , takeLE
141141 , takeByTime
142142 -- By elements
143143 , sliceSepBy
@@ -715,10 +715,10 @@ rollingHash = rollingHashWithSalt defaultSalt
715715-- | Compute an 'Int' sized polynomial rolling hash of the first n elements of
716716-- a stream.
717717--
718−-- > rollingHashFirstN = ltake n rollingHash
718+-- > rollingHashFirstN = takeLE n rollingHash
719719{-# INLINABLE rollingHashFirstN #-}
720720rollingHashFirstN :: (Monad m, Enum a) => Int -> Fold m a Int64
721−rollingHashFirstN n = ltake n rollingHash
721+rollingHashFirstN n = takeLE n rollingHash
722722
723723------------------------------------------------------------------------------
724724-- Monoidal left folds
@@ -826,7 +826,7 @@ toListRevF = mkAccum_ (flip (:)) []
826826-- and discarding the results.
827827{-# INLINABLE drainN #-}
828828drainN :: Monad m => Int -> Fold m a ()
829−drainN n = ltake n drain
829+drainN n = takeLE n drain
830830
831831------------------------------------------------------------------------------
832832-- To Elements
@@ -1056,7 +1056,7 @@ or = any (== True)
10561056-- >>> splitAt_ 4 [1,2,3]
10571057-- > ([1,2,3],[])
10581058--
1059−-- > splitAt n f1 f2 = splitWith (,) (ltake n f1) f2
1059+-- > splitAt n f1 f2 = splitWith (,) (takeLE n f1) f2
10601060--
10611061-- /Internal/
10621062
@@ -1067,7 +1067,7 @@ splitAt
10671067 -> Fold m a b
10681068 -> Fold m a c
10691069 -> Fold m a (b, c)
1070−splitAt n fld = splitWith (,) (ltake n fld)
1070+splitAt n fld = splitWith (,) (takeLE n fld)
10711071
10721072------------------------------------------------------------------------------
10731073-- Element Aware APIs
@@ -1176,7 +1176,7 @@ sliceSepBy predicate (Fold fstep finitial fextract) =
11761176{-# INLINABLE sliceSepByMax #-}
11771177sliceSepByMax :: Monad m
11781178 => (a -> Bool) -> Int -> Fold m a b -> Fold m a b
1179−sliceSepByMax p n = sliceSepBy p . ltake n
1179+sliceSepByMax p n = sliceSepBy p . takeLE n
11801180
11811181-- | Collect stream elements until an element succeeds the predicate. Also take
11821182-- the element on which the predicate succeeded. The succeeding element is
src/Streamly/Internal/Data/Fold/Types.hs+8−8
@@ -184,7 +184,7 @@ module Streamly.Internal.Data.Fold.Types
184184 , lfilter
185185 , lfilterM
186186 , lcatMaybes
187− , ltake
187+ , takeLE
188188 , takeByTime
189189
190190 -- * Distributing
@@ -704,18 +704,18 @@ lcatMaybes = lfilter isJust . lmap fromJust
704704
705705-- | Take at most @n@ input elements and fold them using the supplied fold.
706706--
707−-- >>> Stream.fold (Fold.ltake 1 Fold.toList) $ Stream.fromList [1]
707+-- >>> Stream.fold (Fold.takeLE 1 Fold.toList) $ Stream.fromList [1]
708708-- [1]
709709--
710−-- >>> Stream.fold (Fold.ltake (-1) Fold.toList) $ Stream.fromList [1]
710+-- >>> Stream.fold (Fold.takeLE (-1) Fold.toList) $ Stream.fromList [1]
711711-- []
712712--
713713-- /Internal/
714714--
715715-- @since 0.7.0
716−{-# INLINE ltake #-}
717−ltake :: Monad m => Int -> Fold m a b -> Fold m a b
718−ltake n (Fold fstep finitial fextract) = Fold step initial extract
716+{-# INLINE takeLE #-}
717+takeLE :: Monad m => Int -> Fold m a b -> Fold m a b
718+takeLE n (Fold fstep finitial fextract) = Fold step initial extract
719719
720720 where
721721
@@ -862,7 +862,7 @@ many (Fold cstep cinitial cextract) (Fold sstep sinitial sextract) =
862862-- of @n@ items in the input stream and supplies the result to the @collect@
863863-- fold.
864864--
865−-- > lchunksOf n split collect = many collect (ltake n split)
865+-- > lchunksOf n split collect = many collect (takeLE n split)
866866--
867867-- Stops when @collect@ stops.
868868--
@@ -870,7 +870,7 @@ many (Fold cstep cinitial cextract) (Fold sstep sinitial sextract) =
870870--
871871{-# INLINE lchunksOf #-}
872872lchunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
873−lchunksOf n split collect = many collect (ltake n split)
873+lchunksOf n split collect = many collect (takeLE n split)
874874
875875{-# INLINE lchunksOf2 #-}
876876lchunksOf2 :: Monad m => Int -> Fold m a b -> Fold2 m x b c -> Fold2 m x a c
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1
@@ -382,7 +382,7 @@ drain = P.drain
382382
383383-- |
384384-- > drainN n = drain . take n
385−-- > drainN n = fold (Fold.ltake n Fold.drain)
385+-- > drainN n = fold (Fold.takeLE n Fold.drain)
386386--
387387-- Run maximum up to @n@ iterations of a stream.
388388--
src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+5−5
@@ -877,7 +877,7 @@ iterateMapLeftsWith combine f = iterateMapWith combine (either f (const K.nil))
877877-- This is the streaming dual of the 'Streamly.Internal.Data.Fold.many'
878878-- parse combinator.
879879--
880−-- >>> f = Fold.ltake 2 Fold.sum
880+-- >>> f = Fold.takeLE 2 Fold.sum
881881-- >>> Stream.toList $ Stream.foldMany f $ Stream.fromList [1..10]
882882-- > [3,7,11,15,19]
883883--
@@ -912,7 +912,7 @@ foldSequence _f _m = undefined
912912-- generate the first fold, the fold is applied on the stream and the result of
913913-- the fold is used to generate the next fold and so on.
914914--
915−-- >>> f x = Fold.ltake 2 (Fold.mconcatTo x)
915+-- >>> f x = Fold.takeLE 2 (Fold.mconcatTo x)
916916-- >>> s = Stream.map Sum $ Stream.fromList [1..10]
917917-- >>> Stream.toList $ Stream.map getSum $ Stream.foldIterate f 0 s
918918-- > [3,10,21,36,55,55]
@@ -1535,15 +1535,15 @@ splitOnSuffixSeqAny subseq f m = undefined
15351535-- >> S.toList $ S.chunksOf 2 FL.sum (S.enumerateFromTo 1 10)
15361536-- > [3,7,11,15,19]
15371537--
1538−-- This can be considered as an n-fold version of 'ltake' where we apply
1539−-- 'ltake' repeatedly on the leftover stream until the stream exhausts.
1538+-- This can be considered as an n-fold version of 'takeLE' where we apply
1539+-- 'takeLE' repeatedly on the leftover stream until the stream exhausts.
15401540--
15411541-- @since 0.7.0
15421542{-# INLINE chunksOf #-}
15431543chunksOf
15441544 :: (IsStream t, Monad m)
15451545 => Int -> Fold m a b -> t m a -> t m b
1546−chunksOf n f = foldMany (FL.ltake n f)
1546+chunksOf n f = foldMany (FL.takeLE n f)
15471547
15481548-- |
15491549--
test/Streamly/Test/Data/Fold.hs+4−4
@@ -215,10 +215,10 @@ and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
215215or :: [Bool] -> Expectation
216216or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
217217
218−ltake :: [Int] -> Property
219−ltake ls =
218+takeLE :: [Int] -> Property
219+takeLE ls =
220220 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
221− S.fold (F.ltake n FL.toList) (S.fromList ls)
221+ S.fold (F.takeLE n FL.toList) (S.fromList ls)
222222 `shouldReturn` Prelude.take n ls
223223
224224sliceSepBy :: Property
@@ -443,7 +443,7 @@ main = hspec $
443443 prop "And" Main.and
444444 prop "Or" Main.or
445445 prop "mapMaybe" mapMaybe
446− prop "ltake" ltake
446+ prop "takeLE" takeLE
447447 prop "sliceSepBy" sliceSepBy
448448 prop "sliceSepByMax" sliceSepByMax
449449 prop "drain" Main.drain
test/Streamly/Test/Data/Parser.hs+6−6
@@ -535,8 +535,8 @@ applicative =
535535 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
536536 let parser =
537537 (,)
538− <$> P.fromFold (FL.ltake (length list1) FL.toList)
539− <*> P.fromFold (FL.ltake (length list2) FL.toList)
538+ <$> P.fromFold (FL.takeLE (length list1) FL.toList)
539+ <*> P.fromFold (FL.takeLE (length list2) FL.toList)
540540 in monadicIO $ do
541541 (olist1, olist2) <-
542542 run $ S.parse parser (S.fromList $ list1 ++ list2)
@@ -546,7 +546,7 @@ applicative =
546546sequence :: Property
547547sequence =
548548 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
549− let p xs = P.fromFold (FL.ltake (length xs) FL.toList)
549+ let p xs = P.fromFold (FL.takeLE (length xs) FL.toList)
550550 in monadicIO $ do
551551 outs <- run $
552552 S.parse
@@ -559,8 +559,8 @@ monad =
559559 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
560560 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
561561 let parser = do
562− olist1 <- P.fromFold (FL.ltake (length list1) FL.toList)
563− olist2 <- P.fromFold (FL.ltake (length list2) FL.toList)
562+ olist1 <- P.fromFold (FL.takeLE (length list1) FL.toList)
563+ olist2 <- P.fromFold (FL.takeLE (length list2) FL.toList)
564564 return (olist1, olist2)
565565 in monadicIO $ do
566566 (olist1, olist2) <-
@@ -578,7 +578,7 @@ parseMany =
578578 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
579579 monadicIO $ do
580580 outs <- do
581− let p = P.fromFold $ FL.ltake len FL.toList
581+ let p = P.fromFold $ FL.takeLE len FL.toList
582582 run
583583 $ S.toList
584584 $ S.parseMany p (S.fromList $ concat ins)
test/Streamly/Test/Data/Parser/ParserD.hs+10−10
@@ -182,7 +182,7 @@ take :: Property
182182take =
183183 forAll (chooseInt (min_value, max_value)) $ \n ->
184184 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
185− case S.parseD (P.fromFold $ FL.ltake n FL.toList) (S.fromList ls) of
185+ case S.parseD (P.fromFold $ FL.takeLE n FL.toList) (S.fromList ls) of
186186 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
187187 Left _ -> property False
188188
@@ -263,7 +263,7 @@ lookAheadPass :: Property
263263lookAheadPass =
264264 forAll (chooseInt (min_value, max_value)) $ \n ->
265265 let
266− takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.ltake n FL.toList
266+ takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.takeLE n FL.toList
267267 parseTwice = do
268268 parsed_list_1 <- takeWithoutConsume
269269 parsed_list_2 <- takeWithoutConsume
@@ -279,7 +279,7 @@ lookAhead :: Property
279279lookAhead =
280280 forAll (chooseInt (min_value, max_value)) $ \n ->
281281 let
282− takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.ltake n FL.toList
282+ takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.takeLE n FL.toList
283283 parseTwice = do
284284 parsed_list_1 <- takeWithoutConsume
285285 parsed_list_2 <- takeWithoutConsume
@@ -396,7 +396,7 @@ teeWithPass =
396396 forAll (chooseInt (min_value, max_value)) $ \n ->
397397 forAll (listOf (chooseInt (0, 1))) $ \ls ->
398398 let
399− prsr = P.fromFold $ FL.ltake n FL.toList
399+ prsr = P.fromFold $ FL.takeLE n FL.toList
400400 in
401401 case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
402402 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
@@ -536,8 +536,8 @@ applicative =
536536 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
537537 let parser =
538538 (,)
539− <$> P.fromFold (FL.ltake (length list1) FL.toList)
540− <*> P.fromFold (FL.ltake (length list2) FL.toList)
539+ <$> P.fromFold (FL.takeLE (length list1) FL.toList)
540+ <*> P.fromFold (FL.takeLE (length list2) FL.toList)
541541 in monadicIO $ do
542542 (olist1, olist2) <-
543543 run $ S.parseD parser (S.fromList $ list1 ++ list2)
@@ -547,7 +547,7 @@ applicative =
547547sequence :: Property
548548sequence =
549549 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
550− let parsers = fmap (\xs -> P.fromFold $ FL.ltake (length xs) FL.toList) ins
550+ let parsers = fmap (\xs -> P.fromFold $ FL.takeLE (length xs) FL.toList) ins
551551 in monadicIO $ do
552552 outs <- run $
553553 S.parseD
@@ -560,8 +560,8 @@ monad =
560560 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
561561 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
562562 let parser = do
563− olist1 <- P.fromFold (FL.ltake (length list1) FL.toList)
564− olist2 <- P.fromFold (FL.ltake (length list2) FL.toList)
563+ olist1 <- P.fromFold (FL.takeLE (length list1) FL.toList)
564+ olist2 <- P.fromFold (FL.takeLE (length list2) FL.toList)
565565 return (olist1, olist2)
566566 in monadicIO $ do
567567 (olist1, olist2) <-
@@ -582,7 +582,7 @@ parseMany =
582582 ( run
583583 $ S.toList
584584 $ S.parseManyD
585− (P.fromFold $ FL.ltake len FL.toList) (S.fromList $ concat ins)
585+ (P.fromFold $ FL.takeLE len FL.toList) (S.fromList $ concat ins)
586586 )
587587 listEquals (==) outs ins
588588