on master help sign in
Rename takeLE to take
0414fe8Ranjeet Kumar Ranjan
benchmark/Streamly/Benchmark/Data/Fold.hs+8−7
@@ -64,13 +64,14 @@ any value = IP.fold (FL.any (> value))
64all :: (Monad m, Ord a) => a -> SerialT m a -> m Bool
64all :: (Monad m, Ord a) => a -> SerialT m a -> m Bool
65all value = IP.fold (FL.all (<= value))
65all value = IP.fold (FL.all (<= value))
66
66
67−{-# INLINE takeLE #-}
67+{-# INLINE take #-}
68−takeLE :: Monad m => Int -> SerialT m a -> m ()
68+take :: Monad m => Int -> SerialT m a -> m ()
69−takeLE value = IP.fold (FL.takeLE value FL.drain)
69+take value = IP.fold (FL.take value FL.drain)
70
70
71{-# INLINE sequence_ #-}
71{-# INLINE sequence_ #-}
72sequence_ :: Monad m => Int -> Fold m a ()
72sequence_ :: Monad m => Int -> Fold m a ()
73+sequence_ value =
73−sequence_ value = foldr f (FL.yield ()) (Prelude.replicate value (FL.takeLE 1 FL.drain))
74+ foldr f (FL.yield ()) (Prelude.replicate value (FL.take 1 FL.drain))
74
75
75 where
76 where
76
77
@@ -87,7 +88,7 @@ sliceSepBy value = IP.fold (FL.sliceSepBy (>= value) FL.drain)
87
88
88{-# INLINE many #-}
89{-# INLINE many #-}
89many :: Monad m => SerialT m Int -> m ()
90many :: Monad m => SerialT m Int -> m ()
90−many = IP.fold (FL.many FL.drain (FL.takeLE 1 FL.drain))
91+many = IP.fold (FL.many FL.drain (FL.take 1 FL.drain))
91
92
92{-# INLINE splitAllAny #-}
93{-# INLINE splitAllAny #-}
93splitAllAny :: Monad m => Int -> SerialT m Int -> m (Bool, Bool)
94splitAllAny :: Monad m => Int -> SerialT m Int -> m (Bool, Bool)
@@ -242,7 +243,7 @@ o_1_space_serial_elimination value =
242 , benchIOSink value "notElem" (S.fold (FL.notElem (value + 1)))
243 , benchIOSink value "notElem" (S.fold (FL.notElem (value + 1)))
243 , benchIOSink value "all" $ all value
244 , benchIOSink value "all" $ all value
244 , benchIOSink value "any" $ any value
245 , benchIOSink value "any" $ any value
245− , benchIOSink value "takeLE" $ takeLE value
246+ , benchIOSink value "take" $ take value
246 , benchIOSink value "sliceSepBy" $ sliceSepBy value
247 , benchIOSink value "sliceSepBy" $ sliceSepBy value
247 , benchIOSink value "and" (S.fold FL.and . S.map (<= (value + 1)))
248 , benchIOSink value "and" (S.fold FL.and . S.map (<= (value + 1)))
248 , benchIOSink value "or" (S.fold FL.or . S.map (> (value + 1)))
249 , benchIOSink value "or" (S.fold FL.or . S.map (> (value + 1)))
@@ -277,7 +278,7 @@ o_1_space_serial_composition value =
277 "composition"
278 "composition"
278 [ benchIOSink value "splitWith (all, any)" $ splitAllAny value
279 [ benchIOSink value "splitWith (all, any)" $ splitAllAny value
279 , benchIOSink value "tee (all, any)" $ teeAllAny value
280 , benchIOSink value "tee (all, any)" $ teeAllAny value
280− , benchIOSink value "many drain (takeLE 1)" many
281+ , benchIOSink value "many drain (take 1)" many
281 , benchIOSink value "tee (sum, length)" teeSumLength
282 , benchIOSink value "tee (sum, length)" teeSumLength
282 , benchIOSink value "distribute [sum, length]" distribute
283 , benchIOSink value "distribute [sum, length]" distribute
283 , benchIOSink value "partition (sum, length)" partition
284 , benchIOSink value "partition (sum, length)" partition
benchmark/Streamly/Benchmark/Data/Parser.hs+4−4
@@ -235,7 +235,7 @@ parseManyChunksOfSum :: Int -> Handle -> IO Int
235parseManyChunksOfSum n inh =
235parseManyChunksOfSum n inh =
236 S.length
236 S.length
237 $ IP.parseMany
237 $ IP.parseMany
238− (PR.fromFold $ FL.takeLE n FL.sum)
238+ (PR.fromFold $ FL.take n FL.sum)
239 (S.unfold Handle.read inh)
239 (S.unfold Handle.read inh)
240
240
241-------------------------------------------------------------------------------
241-------------------------------------------------------------------------------
@@ -246,7 +246,7 @@ parseManyChunksOfSum n inh =
246parseManyUnfoldArrays :: Int -> [Array.Array Int] -> IO ()
246parseManyUnfoldArrays :: Int -> [Array.Array Int] -> IO ()
247parseManyUnfoldArrays count arrays = do
247parseManyUnfoldArrays count arrays = do
248 let src = Source.source (Just (Producer.OuterLoop arrays))
248 let src = Source.source (Just (Producer.OuterLoop arrays))
249− let parser = PR.fromFold (FL.takeLE count FL.drain)
249+ let parser = PR.fromFold (FL.take count FL.drain)
250 let readSrc =
250 let readSrc =
251 Source.producer
251 Source.producer
252 $ Producer.concat Producer.fromList Array.producer
252 $ Producer.concat Producer.fromList Array.producer
@@ -304,7 +304,7 @@ parseMany :: MonadCatch m => Int -> SerialT m Int -> m ()
304parseMany n =
304parseMany n =
305 S.drain
305 S.drain
306 . S.map getSum
306 . S.map getSum
307− . IP.parseMany (PR.fromFold $ FL.takeLE n FL.mconcat)
307+ . IP.parseMany (PR.fromFold $ FL.take n FL.mconcat)
308 . S.map Sum
308 . S.map Sum
309
309
310{-# INLINE parseIterate #-}
310{-# INLINE parseIterate #-}
@@ -312,7 +312,7 @@ parseIterate :: MonadCatch m => Int -> SerialT m Int -> m ()
312parseIterate n =
312parseIterate n =
313 S.drain
313 S.drain
314 . S.map getSum
314 . S.map getSum
315− . IP.parseIterate (PR.fromFold . FL.takeLE n . FL.sconcat) (Sum 0)
315+ . IP.parseIterate (PR.fromFold . FL.take n . FL.sconcat) (Sum 0)
316 . S.map Sum
316 . S.map Sum
317
317
318-------------------------------------------------------------------------------
318-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+1−1
@@ -220,7 +220,7 @@ parseManyGroupsRolling b =
220parseManyUnfoldArrays :: Int -> [Array.Array Int] -> IO ()
220parseManyUnfoldArrays :: Int -> [Array.Array Int] -> IO ()
221parseManyUnfoldArrays count arrays = do
221parseManyUnfoldArrays count arrays = do
222 let src = Source.source (Just (Producer.OuterLoop arrays))
222 let src = Source.source (Just (Producer.OuterLoop arrays))
223− let parser = PR.fromFold (FL.takeLE count FL.drain)
223+ let parser = PR.fromFold (FL.take count FL.drain)
224 let readSrc =
224 let readSrc =
225 Source.producer
225 Source.producer
226 $ Producer.concat Producer.fromList Array.producer
226 $ Producer.concat Producer.fromList Array.producer
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+2−2
@@ -311,11 +311,11 @@ chunksOfSum n inh = S.length $ S.chunksOf n FL.sum (S.unfold FH.read inh)
311
311
312foldManyPostChunksOfSum :: Int -> Handle -> IO Int
312foldManyPostChunksOfSum :: Int -> Handle -> IO Int
313foldManyPostChunksOfSum n inh =
313foldManyPostChunksOfSum n inh =
314− S.length $ IP.foldManyPost (FL.takeLE n FL.sum) (S.unfold FH.read inh)
314+ S.length $ IP.foldManyPost (FL.take n FL.sum) (S.unfold FH.read inh)
315
315
316foldManyChunksOfSum :: Int -> Handle -> IO Int
316foldManyChunksOfSum :: Int -> Handle -> IO Int
317foldManyChunksOfSum n inh =
317foldManyChunksOfSum n inh =
318− S.length $ IP.foldMany (FL.takeLE n FL.sum) (S.unfold FH.read inh)
318+ S.length $ IP.foldMany (FL.take n FL.sum) (S.unfold FH.read inh)
319
319
320-- XXX investigate why we need an INLINE in this case (GHC)
320-- XXX investigate why we need an INLINE in this case (GHC)
321-- Even though allocations remain the same in both cases inlining improves time
321-- Even though allocations remain the same in both cases inlining improves time
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation2.hs+2−2
@@ -138,7 +138,7 @@ foldMany :: Monad m => SerialT m Int -> m ()
138foldMany =
138foldMany =
139 S.drain
139 S.drain
140 . S.map getSum
140 . S.map getSum
141− . Internal.foldMany (FL.takeLE 2 FL.mconcat)
141+ . Internal.foldMany (FL.take 2 FL.mconcat)
142 . S.map Sum
142 . S.map Sum
143
143
144{-# INLINE _foldIterate #-}
144{-# INLINE _foldIterate #-}
@@ -146,7 +146,7 @@ _foldIterate :: Monad m => SerialT m Int -> m ()
146_foldIterate =
146_foldIterate =
147 S.drain
147 S.drain
148 . S.map getSum
148 . S.map getSum
149− . Internal.foldIterate (FL.takeLE 2 . FL.sconcat) (Sum 0)
149+ . Internal.foldIterate (FL.take 2 . FL.sconcat) (Sum 0)
150 . S.map Sum
150 . S.map Sum
151
151
152o_1_space_grouping :: Int -> [Benchmark]
152o_1_space_grouping :: Int -> [Benchmark]
src/Streamly/Data/Fold.hs+1−1
@@ -175,7 +175,7 @@ module Streamly.Data.Fold
175
175
176 {-
176 {-
177 -- ** Trimming
177 -- ** Trimming
178− , takeLE
178+ , take
179 -- takeByTime
179 -- takeByTime
180 , ldrop
180 , ldrop
181 , ldropWhile
181 , ldropWhile
src/Streamly/Internal/Data/Array/Foreign/Mut/Types.hs+1−1
@@ -789,7 +789,7 @@ writeNAllocWith alloc n = Fold step initial extract
789-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
789-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
790-- 'Array'.
790-- 'Array'.
791--
791--
792−-- @writeN n = Fold.takeLE n writeNUnsafe@
792+-- @writeN n = Fold.take n writeNUnsafe@
793--
793--
794-- @since 0.7.0
794-- @since 0.7.0
795{-# INLINE_NORMAL writeN #-}
795{-# INLINE_NORMAL writeN #-}
src/Streamly/Internal/Data/Fold.hs+6−6
@@ -143,7 +143,7 @@ module Streamly.Internal.Data.Fold
143 -}
143 -}
144
144
145 -- ** Trimming
145 -- ** Trimming
146− , takeLE
146+ , take
147 , takeByTime
147 , takeByTime
148 -- By elements
148 -- By elements
149 , sliceSepBy
149 , sliceSepBy
@@ -643,10 +643,10 @@ rollingHash = rollingHashWithSalt defaultSalt
643-- | Compute an 'Int' sized polynomial rolling hash of the first n elements of
643-- | Compute an 'Int' sized polynomial rolling hash of the first n elements of
644-- a stream.
644-- a stream.
645--
645--
646−-- > rollingHashFirstN = takeLE n rollingHash
646+-- > rollingHashFirstN = take n rollingHash
647{-# INLINABLE rollingHashFirstN #-}
647{-# INLINABLE rollingHashFirstN #-}
648rollingHashFirstN :: (Monad m, Enum a) => Int -> Fold m a Int64
648rollingHashFirstN :: (Monad m, Enum a) => Int -> Fold m a Int64
649−rollingHashFirstN n = takeLE n rollingHash
649+rollingHashFirstN n = take n rollingHash
650
650
651------------------------------------------------------------------------------
651------------------------------------------------------------------------------
652-- Monoidal left folds
652-- Monoidal left folds
@@ -741,7 +741,7 @@ toListRev = mkAccum_ (flip (:)) []
741-- and discarding the results.
741-- and discarding the results.
742{-# INLINABLE drainN #-}
742{-# INLINABLE drainN #-}
743drainN :: Monad m => Int -> Fold m a ()
743drainN :: Monad m => Int -> Fold m a ()
744−drainN n = takeLE n drain
744+drainN n = take n drain
745
745
746------------------------------------------------------------------------------
746------------------------------------------------------------------------------
747-- To Elements
747-- To Elements
@@ -971,7 +971,7 @@ or = any (== True)
971-- >>> splitAt_ 4 [1,2,3]
971-- >>> splitAt_ 4 [1,2,3]
972-- ([1,2,3],[])
972-- ([1,2,3],[])
973--
973--
974−-- > splitAt n f1 f2 = splitWith (,) (takeLE n f1) f2
974+-- > splitAt n f1 f2 = splitWith (,) (take n f1) f2
975--
975--
976-- /Pre-release/
976-- /Pre-release/
977
977
@@ -982,7 +982,7 @@ splitAt
982 -> Fold m a b
982 -> Fold m a b
983 -> Fold m a c
983 -> Fold m a c
984 -> Fold m a (b, c)
984 -> Fold m a (b, c)
985−splitAt n fld = splitWith (,) (takeLE n fld)
985+splitAt n fld = splitWith (,) (take n fld)
986
986
987------------------------------------------------------------------------------
987------------------------------------------------------------------------------
988-- Element Aware APIs
988-- Element Aware APIs
src/Streamly/Internal/Data/Fold/Types.hs+10−10
@@ -199,7 +199,7 @@ module Streamly.Internal.Data.Fold.Types
199 , filter
199 , filter
200 , filterM
200 , filterM
201 , lcatMaybes
201 , lcatMaybes
202− , takeLE
202+ , take
203 , takeByTime
203 , takeByTime
204
204
205 -- * Distributing
205 -- * Distributing
@@ -241,7 +241,7 @@ import Fusion.Plugin.Types (Fuse(..))
241import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
241import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
242import Streamly.Internal.Data.SVar (MonadAsync)
242import Streamly.Internal.Data.SVar (MonadAsync)
243
243
244−import Prelude hiding (concatMap, filter, map)
244+import Prelude hiding (concatMap, filter, map, take)
245
245
246-- $setup
246-- $setup
247-- >>> :m
247-- >>> :m
@@ -682,7 +682,7 @@ data ConcatMapState m sa a c
682-- Compare with 'Monad' instance method '>>='.
682-- Compare with 'Monad' instance method '>>='.
683--
683--
684-- >>> import Data.Maybe (fromJust)
684-- >>> import Data.Maybe (fromJust)
685−-- >>> Stream.fold (Fold.concatMap (flip Fold.takeLE Fold.sum) (Fold.rmapM (return . fromJust) Fold.head)) $ Stream.fromList [10,9..1]
685+-- >>> Stream.fold (Fold.concatMap (flip Fold.take Fold.sum) (Fold.rmapM (return . fromJust) Fold.head)) $ Stream.fromList [10,9..1]
686-- 45
686-- 45
687--
687--
688-- /Pre-release/
688-- /Pre-release/
@@ -796,18 +796,18 @@ lcatMaybes = filter isJust . map fromJust
796
796
797-- | Take at most @n@ input elements and fold them using the supplied fold.
797-- | Take at most @n@ input elements and fold them using the supplied fold.
798--
798--
799−-- >>> Stream.fold (Fold.takeLE 1 Fold.toList) $ Stream.fromList [1]
799+-- >>> Stream.fold (Fold.take 1 Fold.toList) $ Stream.fromList [1]
800-- [1]
800-- [1]
801--
801--
802−-- >>> Stream.fold (Fold.takeLE (-1) Fold.toList) $ Stream.fromList [1]
802+-- >>> Stream.fold (Fold.take (-1) Fold.toList) $ Stream.fromList [1]
803-- []
803-- []
804--
804--
805-- /Pre-release/
805-- /Pre-release/
806--
806--
807-- @since 0.7.0
807-- @since 0.7.0
808−{-# INLINE takeLE #-}
808+{-# INLINE take #-}
809−takeLE :: Monad m => Int -> Fold m a b -> Fold m a b
809+take :: Monad m => Int -> Fold m a b -> Fold m a b
810−takeLE n (Fold fstep finitial fextract) = Fold step initial extract
810+take n (Fold fstep finitial fextract) = Fold step initial extract
811
811
812 where
812 where
813
813
@@ -954,7 +954,7 @@ many (Fold cstep cinitial cextract) (Fold sstep sinitial sextract) =
954-- of @n@ items in the input stream and supplies the result to the @collect@
954-- of @n@ items in the input stream and supplies the result to the @collect@
955-- fold.
955-- fold.
956--
956--
957−-- > chunksOf n split collect = many collect (takeLE n split)
957+-- > chunksOf n split collect = many collect (take n split)
958--
958--
959-- Stops when @collect@ stops.
959-- Stops when @collect@ stops.
960--
960--
@@ -962,7 +962,7 @@ many (Fold cstep cinitial cextract) (Fold sstep sinitial sextract) =
962--
962--
963{-# INLINE chunksOf #-}
963{-# INLINE chunksOf #-}
964chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
964chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
965−chunksOf n split collect = many collect (takeLE n split)
965+chunksOf n split collect = many collect (take n split)
966
966
967{-# INLINE chunksOf2 #-}
967{-# INLINE chunksOf2 #-}
968chunksOf2 :: Monad m => Int -> Fold m a b -> Fold2 m x b c -> Fold2 m x a c
968chunksOf2 :: Monad m => Int -> Fold m a b -> Fold2 m x b c -> Fold2 m x a c
src/Streamly/Internal/Data/Parser.hs+1−1
@@ -379,7 +379,7 @@ either = K.toParserK . D.either
379-- be defined in terms of takeBetween. For example:
379-- be defined in terms of takeBetween. For example:
380--
380--
381-- @
381-- @
382−-- take = takeBetween 0 n -- equivalent of takeLE
382+-- take = takeBetween 0 n -- equivalent of take
383-- take1 = takeBetween 1 n -- equivalent of takeLE1
383-- take1 = takeBetween 1 n -- equivalent of takeLE1
384-- takeEQ = takeBetween n n
384-- takeEQ = takeBetween n n
385-- takeGE = takeBetween n maxBound
385-- takeGE = takeBetween n maxBound
src/Streamly/Internal/Data/Parser/ParserD.hs+1−1
@@ -45,7 +45,7 @@ module Streamly.Internal.Data.Parser.ParserD
45 --
45 --
46 -- Grab a sequence of input elements without inspecting them
46 -- Grab a sequence of input elements without inspecting them
47 , takeBetween
47 , takeBetween
48− -- , takeLE -- take -- takeBetween 0 n
48+ -- , take -- take -- takeBetween 0 n
49 -- , takeLE1 -- take1 -- takeBetween 1 n
49 -- , takeLE1 -- take1 -- takeBetween 1 n
50 , takeEQ -- takeBetween n n
50 , takeEQ -- takeBetween n n
51 , takeGE -- takeBetween n maxBound
51 , takeGE -- takeBetween n maxBound
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1
@@ -398,7 +398,7 @@ drain = P.drain
398
398
399-- |
399-- |
400-- > drainN n = drain . take n
400-- > drainN n = drain . take n
401−-- > drainN n = fold (Fold.takeLE n Fold.drain)
401+-- > drainN n = fold (Fold.take n Fold.drain)
402--
402--
403-- Run maximum up to @n@ iterations of a stream.
403-- Run maximum up to @n@ iterations of a stream.
404--
404--
src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+7−7
@@ -946,7 +946,7 @@ iterateMapLeftsWith combine f = iterateMapWith combine (either f (const K.nil))
946-- | Like 'foldMany' but appends empty fold output if the fold and stream
946-- | Like 'foldMany' but appends empty fold output if the fold and stream
947-- termination aligns:
947-- termination aligns:
948--
948--
949−-- >>> f = Fold.takeLE 2 Fold.sum
949+-- >>> f = Fold.take 2 Fold.sum
950-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList []
950-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList []
951-- [0]
951-- [0]
952-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..9]
952-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..9]
@@ -969,7 +969,7 @@ foldManyPost f m = D.fromStreamD $ D.foldManyPost f (D.toStreamD m)
969--
969--
970-- To sum every two contiguous elements in a stream:
970-- To sum every two contiguous elements in a stream:
971--
971--
972−-- >>> f = Fold.takeLE 2 Fold.sum
972+-- >>> f = Fold.take 2 Fold.sum
973-- >>> Stream.toList $ Stream.foldMany f $ Stream.fromList [1..10]
973-- >>> Stream.toList $ Stream.foldMany f $ Stream.fromList [1..10]
974-- [3,7,11,15,19]
974-- [3,7,11,15,19]
975--
975--
@@ -978,7 +978,7 @@ foldManyPost f m = D.fromStreamD $ D.foldManyPost f (D.toStreamD m)
978-- >>> Stream.toList $ Stream.foldMany f $ Stream.fromList []
978-- >>> Stream.toList $ Stream.foldMany f $ Stream.fromList []
979-- []
979-- []
980--
980--
981−-- Note @foldMany (takeLE 0)@ would result in an infinite loop in a non-empty
981+-- Note @foldMany (take 0)@ would result in an infinite loop in a non-empty
982-- stream.
982-- stream.
983--
983--
984-- /Pre-release/
984-- /Pre-release/
@@ -1010,7 +1010,7 @@ foldSequence _f _m = undefined
1010--
1010--
1011-- @
1011-- @
1012-- > import Data.Monoid (Sum(..))
1012-- > import Data.Monoid (Sum(..))
1013−-- > f x = Fold.takeLE 2 (Fold.sconcat x)
1013+-- > f x = Fold.take 2 (Fold.sconcat x)
1014-- > s = Stream.map Sum $ Stream.fromList [1..10]
1014-- > s = Stream.map Sum $ Stream.fromList [1..10]
1015-- > Stream.toList $ Stream.map getSum $ Stream.foldIterate f 0 s
1015-- > Stream.toList $ Stream.map getSum $ Stream.foldIterate f 0 s
1016-- [3,10,21,36,55,55]
1016-- [3,10,21,36,55,55]
@@ -1715,10 +1715,10 @@ splitOnSuffixSeqAny subseq f m = undefined
1715-- >>> Stream.toList $ Stream.chunksOf 2 Fold.sum (Stream.enumerateFromTo 1 10)
1715-- >>> Stream.toList $ Stream.chunksOf 2 Fold.sum (Stream.enumerateFromTo 1 10)
1716-- [3,7,11,15,19]
1716-- [3,7,11,15,19]
1717--
1717--
1718−-- This can be considered as an n-fold version of 'takeLE' where we apply
1718+-- This can be considered as an n-fold version of 'take' where we apply
1719−-- 'takeLE' repeatedly on the leftover stream until the stream exhausts.
1719+-- 'take' repeatedly on the leftover stream until the stream exhausts.
1720--
1720--
1721−-- @chunksOf n f = foldMany (FL.takeLE n f)@
1721+-- @chunksOf n f = foldMany (FL.take n f)@
1722--
1722--
1723-- @since 0.7.0
1723-- @since 0.7.0
1724{-# INLINE chunksOf #-}
1724{-# INLINE chunksOf #-}
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+1−1
@@ -898,7 +898,7 @@ foldMany (Fold fstep initial extract) (Stream step state) =
898
898
899{-# INLINE chunksOf #-}
899{-# INLINE chunksOf #-}
900chunksOf :: Monad m => Int -> Fold m a b -> Stream m a -> Stream m b
900chunksOf :: Monad m => Int -> Fold m a b -> Stream m a -> Stream m b
901−chunksOf n f = foldMany (FL.takeLE n f)
901+chunksOf n f = foldMany (FL.take n f)
902
902
903data GroupState2 s fs
903data GroupState2 s fs
904 = GroupStart2 s
904 = GroupStart2 s
src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1
@@ -787,7 +787,7 @@ readOneEvent cfg wt@(Watch _ wdMap) = do
787 pth <-
787 pth <-
788 PR.fromFold
788 PR.fromFold
789 $ FL.sliceSepBy (== 0)
789 $ FL.sliceSepBy (== 0)
790− $ FL.takeLE pathLen (A.writeN pathLen)
790+ $ FL.take pathLen (A.writeN pathLen)
791 let remaining = pathLen - A.length pth - 1
791 let remaining = pathLen - A.length pth - 1
792 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
792 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
793 return pth
793 return pth
test/Streamly/Test/Data/Fold.hs+9−9
@@ -22,7 +22,7 @@ import qualified Streamly.Prelude as S
22import qualified Streamly.Data.Fold as FL
22import qualified Streamly.Data.Fold as FL
23
23
24import Prelude hiding
24import Prelude hiding
25− (maximum, minimum, elem, notElem, null, product, sum, head, last)
25+ (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
26import Test.Hspec as H
26import Test.Hspec as H
27import Test.Hspec.QuickCheck
27import Test.Hspec.QuickCheck
28
28
@@ -147,7 +147,7 @@ find f ls = do
147 let fld = S.fold (FL.find f) (S.fromList ls)
147 let fld = S.fold (FL.find f) (S.fromList ls)
148 in fld `shouldReturn` Nothing
148 in fld `shouldReturn` Nothing
149 Just idx ->
149 Just idx ->
150− let fld = S.fold (FL.any f) (S.fromList $ take idx ls)
150+ let fld = S.fold (FL.any f) (S.fromList $ Prelude.take idx ls)
151 in fld `shouldReturn` False
151 in fld `shouldReturn` False
152
152
153neg :: (a -> Bool) -> a -> Bool
153neg :: (a -> Bool) -> a -> Bool
@@ -165,7 +165,7 @@ findIndex f ls = do
165 then
165 then
166 S.fold (FL.all f) (S.fromList []) `shouldReturn` True
166 S.fold (FL.all f) (S.fromList []) `shouldReturn` True
167 else
167 else
168− S.fold (FL.all f) (S.fromList $ take idx ls)
168+ S.fold (FL.all f) (S.fromList $ Prelude.take idx ls)
169 `shouldReturn` False
169 `shouldReturn` False
170
170
171predicate :: Int -> Bool
171predicate :: Int -> Bool
@@ -179,7 +179,7 @@ elemIndex elm ls = do
179 let fld = S.fold (FL.any (== elm)) (S.fromList ls)
179 let fld = S.fold (FL.any (== elm)) (S.fromList ls)
180 in fld `shouldReturn` False
180 in fld `shouldReturn` False
181 Just idx ->
181 Just idx ->
182− let fld = S.fold (FL.any (== elm)) (S.fromList $ take idx ls)
182+ let fld = S.fold (FL.any (== elm)) (S.fromList $ Prelude.take idx ls)
183 in fld `shouldReturn` False
183 in fld `shouldReturn` False
184
184
185null :: [Int] -> Expectation
185null :: [Int] -> Expectation
@@ -215,10 +215,10 @@ and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
215or :: [Bool] -> Expectation
215or :: [Bool] -> Expectation
216or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
216or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
217
217
218−takeLE :: [Int] -> Property
218+take :: [Int] -> Property
219−takeLE ls =
219+take ls =
220 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
220 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
221− S.fold (F.takeLE n FL.toList) (S.fromList ls)
221+ S.fold (F.take n FL.toList) (S.fromList ls)
222 `shouldReturn` Prelude.take n ls
222 `shouldReturn` Prelude.take n ls
223
223
224sliceSepBy :: Property
224sliceSepBy :: Property
@@ -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.sliceSepBy p (F.takeLE n FL.toList)
239+ f = F.sliceSepBy p (F.take 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
@@ -443,7 +443,7 @@ main = hspec $
443 prop "And" Main.and
443 prop "And" Main.and
444 prop "Or" Main.or
444 prop "Or" Main.or
445 prop "mapMaybe" mapMaybe
445 prop "mapMaybe" mapMaybe
446− prop "takeLE" takeLE
446+ prop "take" take
447 prop "sliceSepBy" sliceSepBy
447 prop "sliceSepBy" sliceSepBy
448 prop "sliceSepByMax" sliceSepByMax
448 prop "sliceSepByMax" sliceSepByMax
449 prop "drain" Main.drain
449 prop "drain" Main.drain
test/Streamly/Test/Data/Parser.hs+6−6
@@ -554,8 +554,8 @@ applicative =
554 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
554 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
555 let parser =
555 let parser =
556 (,)
556 (,)
557− <$> P.fromFold (FL.takeLE (length list1) FL.toList)
557+ <$> P.fromFold (FL.take (length list1) FL.toList)
558− <*> P.fromFold (FL.takeLE (length list2) FL.toList)
558+ <*> P.fromFold (FL.take (length list2) FL.toList)
559 in monadicIO $ do
559 in monadicIO $ do
560 (olist1, olist2) <-
560 (olist1, olist2) <-
561 run $ S.parse parser (S.fromList $ list1 ++ list2)
561 run $ S.parse parser (S.fromList $ list1 ++ list2)
@@ -565,7 +565,7 @@ applicative =
565sequence :: Property
565sequence :: Property
566sequence =
566sequence =
567 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
567 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
568− let p xs = P.fromFold (FL.takeLE (length xs) FL.toList)
568+ let p xs = P.fromFold (FL.take (length xs) FL.toList)
569 in monadicIO $ do
569 in monadicIO $ do
570 outs <- run $
570 outs <- run $
571 S.parse
571 S.parse
@@ -578,8 +578,8 @@ monad =
578 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
578 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
579 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
579 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
580 let parser = do
580 let parser = do
581− olist1 <- P.fromFold (FL.takeLE (length list1) FL.toList)
581+ olist1 <- P.fromFold (FL.take (length list1) FL.toList)
582− olist2 <- P.fromFold (FL.takeLE (length list2) FL.toList)
582+ olist2 <- P.fromFold (FL.take (length list2) FL.toList)
583 return (olist1, olist2)
583 return (olist1, olist2)
584 in monadicIO $ do
584 in monadicIO $ do
585 (olist1, olist2) <-
585 (olist1, olist2) <-
@@ -597,7 +597,7 @@ parseMany =
597 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
597 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
598 monadicIO $ do
598 monadicIO $ do
599 outs <- do
599 outs <- do
600− let p = P.fromFold $ FL.takeLE len FL.toList
600+ let p = P.fromFold $ FL.take len FL.toList
601 run
601 run
602 $ S.toList
602 $ S.toList
603 $ S.parseMany p (S.fromList $ concat ins)
603 $ S.parseMany p (S.fromList $ concat ins)
test/Streamly/Test/Data/Parser/ParserD.hs+12−12
@@ -185,7 +185,7 @@ take :: Property
185take =
185take =
186 forAll (chooseInt (min_value, max_value)) $ \n ->
186 forAll (chooseInt (min_value, max_value)) $ \n ->
187 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
187 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
188− case S.parseD (P.fromFold $ FL.takeLE n FL.toList) (S.fromList ls) of
188+ case S.parseD (P.fromFold $ FL.take n FL.toList) (S.fromList ls) of
189 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
189 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
190 Left _ -> property False
190 Left _ -> property False
191
191
@@ -266,7 +266,7 @@ lookAheadPass :: Property
266lookAheadPass =
266lookAheadPass =
267 forAll (chooseInt (min_value, max_value)) $ \n ->
267 forAll (chooseInt (min_value, max_value)) $ \n ->
268 let
268 let
269− takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.takeLE n FL.toList
269+ takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.take n FL.toList
270 parseTwice = do
270 parseTwice = do
271 parsed_list_1 <- takeWithoutConsume
271 parsed_list_1 <- takeWithoutConsume
272 parsed_list_2 <- takeWithoutConsume
272 parsed_list_2 <- takeWithoutConsume
@@ -282,7 +282,7 @@ lookAhead :: Property
282lookAhead =
282lookAhead =
283 forAll (chooseInt (min_value, max_value)) $ \n ->
283 forAll (chooseInt (min_value, max_value)) $ \n ->
284 let
284 let
285− takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.takeLE n FL.toList
285+ takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.take n FL.toList
286 parseTwice = do
286 parseTwice = do
287 parsed_list_1 <- takeWithoutConsume
287 parsed_list_1 <- takeWithoutConsume
288 parsed_list_2 <- takeWithoutConsume
288 parsed_list_2 <- takeWithoutConsume
@@ -360,7 +360,7 @@ sliceSepByMax :: Property
360sliceSepByMax =
360sliceSepByMax =
361 forAll (chooseInt (min_value, max_value)) $ \n ->
361 forAll (chooseInt (min_value, max_value)) $ \n ->
362 forAll (listOf (chooseInt (0, 1))) $ \ls ->
362 forAll (listOf (chooseInt (0, 1))) $ \ls ->
363− case S.parseD (P.fromFold $ FL.sliceSepBy predicate (FL.takeLE n FL.toList)) (S.fromList ls) of
363+ case S.parseD (P.fromFold $ FL.sliceSepBy predicate (FL.take n FL.toList)) (S.fromList ls) of
364 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
364 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
365 Left _ -> property False
365 Left _ -> property False
366 where
366 where
@@ -417,7 +417,7 @@ teeWithPass =
417 forAll (chooseInt (min_value, max_value)) $ \n ->
417 forAll (chooseInt (min_value, max_value)) $ \n ->
418 forAll (listOf (chooseInt (0, 1))) $ \ls ->
418 forAll (listOf (chooseInt (0, 1))) $ \ls ->
419 let
419 let
420− prsr = P.fromFold $ FL.takeLE n FL.toList
420+ prsr = P.fromFold $ FL.take n FL.toList
421 in
421 in
422 case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
422 case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
423 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
423 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
@@ -557,8 +557,8 @@ applicative =
557 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
557 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
558 let parser =
558 let parser =
559 (,)
559 (,)
560− <$> P.fromFold (FL.takeLE (length list1) FL.toList)
560+ <$> P.fromFold (FL.take (length list1) FL.toList)
561− <*> P.fromFold (FL.takeLE (length list2) FL.toList)
561+ <*> P.fromFold (FL.take (length list2) FL.toList)
562 in monadicIO $ do
562 in monadicIO $ do
563 (olist1, olist2) <-
563 (olist1, olist2) <-
564 run $ S.parseD parser (S.fromList $ list1 ++ list2)
564 run $ S.parseD parser (S.fromList $ list1 ++ list2)
@@ -568,7 +568,7 @@ applicative =
568sequence :: Property
568sequence :: Property
569sequence =
569sequence =
570 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
570 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
571− let parsers = fmap (\xs -> P.fromFold $ FL.takeLE (length xs) FL.toList) ins
571+ let parsers = fmap (\xs -> P.fromFold $ FL.take (length xs) FL.toList) ins
572 in monadicIO $ do
572 in monadicIO $ do
573 outs <- run $
573 outs <- run $
574 S.parseD
574 S.parseD
@@ -581,8 +581,8 @@ monad =
581 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
581 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
582 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
582 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
583 let parser = do
583 let parser = do
584− olist1 <- P.fromFold (FL.takeLE (length list1) FL.toList)
584+ olist1 <- P.fromFold (FL.take (length list1) FL.toList)
585− olist2 <- P.fromFold (FL.takeLE (length list2) FL.toList)
585+ olist2 <- P.fromFold (FL.take (length list2) FL.toList)
586 return (olist1, olist2)
586 return (olist1, olist2)
587 in monadicIO $ do
587 in monadicIO $ do
588 (olist1, olist2) <-
588 (olist1, olist2) <-
@@ -603,7 +603,7 @@ parseMany =
603 ( run
603 ( run
604 $ S.toList
604 $ S.toList
605 $ S.parseManyD
605 $ S.parseManyD
606− (P.fromFold $ FL.takeLE len FL.toList) (S.fromList $ concat ins)
606+ (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
607 )
607 )
608 listEquals (==) outs ins
608 listEquals (==) outs ins
609
609
@@ -622,7 +622,7 @@ parseUnfold = do
622 monadicIO $ do
622 monadicIO $ do
623 arrays <- S.toList $ S.arraysOf clen (S.fromList ls)
623 arrays <- S.toList $ S.arraysOf clen (S.fromList ls)
624 let src = Source.source (Just (Producer.OuterLoop arrays))
624 let src = Source.source (Just (Producer.OuterLoop arrays))
625− let parser = P.fromFold (FL.takeLE tlen FL.toList)
625+ let parser = P.fromFold (FL.take tlen FL.toList)
626 let readSrc =
626 let readSrc =
627 Source.producer
627 Source.producer
628 $ Producer.concat Producer.fromList A.producer
628 $ Producer.concat Producer.fromList A.producer