on master help sign in
Rename stream transformation some APIs

Primary motivation for renaming takeEnd was to avoid confusion with takeEndBy but I like the new name takeLast irrespective of that.

commitbadc62d2b72b7af2f62b2e64bd04bd27a19bcbcf authorHarendra Kumar <harendra@composewell.com> dateFri 12 Mar 2021, 20:21 (6 years ago) parentf261f02
3 files changed+52−53
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation1.hs+15−15 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs−1 src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+37−37
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation1.hs+15−15
@@ -303,14 +303,14 @@ takeWhileTrue value n = composeN n $ S.takeWhile (<= (value + 1))
303303takeWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
304304takeWhileMTrue value n = composeN n $ S.takeWhileM (return . (<= (value + 1)))
305305
306−{-# INLINE takeByTime #-}
307−takeByTime :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
308−takeByTime i n = composeN n (Internal.takeByTime i)
306+{-# INLINE takeInterval #-}
307+takeInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
308+takeInterval i n = composeN n (Internal.takeInterval i)
309309
310310#ifdef INSPECTION
311−-- inspect $ hasNoType 'takeByTime ''SPEC
312−inspect $ hasNoTypeClasses 'takeByTime
313−-- inspect $ 'takeByTime `hasNoType` ''D.Step
311+-- inspect $ hasNoType 'takeInterval ''SPEC
312+inspect $ hasNoTypeClasses 'takeInterval
313+-- inspect $ 'takeInterval `hasNoType` ''D.Step
314314#endif
315315
316316{-# INLINE dropOne #-}
@@ -338,13 +338,13 @@ dropWhileFalse value n = composeN n $ S.dropWhile (> (value + 1))
338338_intervalsOfSum :: MonadAsync m => Double -> Int -> SerialT m Int -> m ()
339339_intervalsOfSum i n = composeN n (S.intervalsOf i FL.sum)
340340
341−{-# INLINE dropByTime #-}
342−dropByTime :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
343−dropByTime i n = composeN n (Internal.dropByTime i)
341+{-# INLINE dropInterval #-}
342+dropInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
343+dropInterval i n = composeN n (Internal.dropInterval i)
344344
345345#ifdef INSPECTION
346−inspect $ hasNoTypeClasses 'dropByTime
347−-- inspect $ 'dropByTime `hasNoType` ''D.Step
346+inspect $ hasNoTypeClasses 'dropInterval
347+-- inspect $ 'dropInterval `hasNoType` ''D.Step
348348#endif
349349
350350{-# INLINE findIndices #-}
@@ -399,16 +399,16 @@ o_1_space_filtering value =
399399 , benchIOSink value "take-all" (takeAll value 1)
400400 , benchIOSink
401401 value
402− "takeByTime-all"
403− (takeByTime (NanoSecond64 maxBound) 1)
402+ "takeInterval-all"
403+ (takeInterval (NanoSecond64 maxBound) 1)
404404 , benchIOSink value "takeWhile-true" (takeWhileTrue value 1)
405405 -- , benchIOSink value "takeWhileM-true" (_takeWhileMTrue value 1)
406406 , benchIOSink value "drop-one" (dropOne 1)
407407 , benchIOSink value "drop-all" (dropAll value 1)
408408 , benchIOSink
409409 value
410− "dropByTime-all"
411− (dropByTime (NanoSecond64 maxBound) 1)
410+ "dropInterval-all"
411+ (dropInterval (NanoSecond64 maxBound) 1)
412412 , benchIOSink value "dropWhile-true" (dropWhileTrue value 1)
413413 -- , benchIOSink value "dropWhileM-true" (_dropWhileMTrue value 1)
414414 , benchIOSink
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs−1
@@ -420,7 +420,6 @@ runN = drainN
420420
421421-- |
422422-- > drainWhile p = drain . takeWhile p
423−-- > drainWhile p = fold (Fold.sliceSepBy (not . p) Fold.drain)
424423--
425424-- Run a stream as long as the predicate holds true.
426425--
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+37−37
@@ -82,20 +82,20 @@ module Streamly.Internal.Data.Stream.IsStream.Transform
8282 -- | Produce a subset of the stream trimmed at ends.
8383
8484 , take
85− , takeByTime -- takeInterval
86− , takeEnd
87− , takeEndInterval
85+ , takeInterval
86+ , takeLast
87+ , takeLastInterval
8888 , takeWhile
8989 , takeWhileM
90− , takeWhileEnd
90+ , takeWhileLast
9191 , takeWhileAround
9292 , drop
93− , dropByTime -- dropInterval
94− , dropEnd
95− , dropEndInterval
93+ , dropInterval
94+ , dropLast
95+ , dropLastInterval
9696 , dropWhile
9797 , dropWhileM
98− , dropWhileEnd
98+ , dropWhileLast
9999 , dropWhileAround
100100
101101 -- * Inserting Elements
@@ -931,27 +931,27 @@ takeWhileM p m = fromStreamD $ D.takeWhileM p $ toStreamD m
931931
932932-- See the lastN fold for impl hints. Use a Data.Array based ring buffer.
933933--
934−-- takeEnd n = Stream.concatM . fmap Array.toStream . fold Fold.lastN
934+-- takeLast n = Stream.concatM . fmap Array.toStream . fold Fold.lastN
935935--
936936-- | Take @n@ elements at the end of the stream.
937937--
938938-- O(n) space, where n is the number elements taken.
939939--
940940-- /Unimplemented/
941−{-# INLINE takeEnd #-}
942−takeEnd :: -- (IsStream t, Monad m) =>
941+{-# INLINE takeLast #-}
942+takeLast :: -- (IsStream t, Monad m) =>
943943 Int -> t m a -> t m a
944−takeEnd = undefined -- fromStreamD $ D.takeEnd n $ toStreamD m
944+takeLast = undefined -- fromStreamD $ D.takeLast n $ toStreamD m
945945
946946-- | Take time interval @i@ seconds at the end of the stream.
947947--
948948-- O(n) space, where n is the number elements taken.
949949--
950950-- /Unimplemented/
951−{-# INLINE takeEndInterval #-}
952−takeEndInterval :: -- (IsStream t, Monad m) =>
951+{-# INLINE takeLastInterval #-}
952+takeLastInterval :: -- (IsStream t, Monad m) =>
953953 Double -> t m a -> t m a
954−takeEndInterval = undefined -- fromStreamD $ D.takeEnd n $ toStreamD m
954+takeLastInterval = undefined -- fromStreamD $ D.takeLast n $ toStreamD m
955955
956956-- | Take all consecutive elements at the end of the stream for which the
957957-- predicate is true.
@@ -959,12 +959,12 @@ takeEndInterval = undefined -- fromStreamD $ D.takeEnd n $ toStreamD m
959959-- O(n) space, where n is the number elements taken.
960960--
961961-- /Unimplemented/
962−{-# INLINE takeWhileEnd #-}
963−takeWhileEnd :: -- (IsStream t, Monad m) =>
962+{-# INLINE takeWhileLast #-}
963+takeWhileLast :: -- (IsStream t, Monad m) =>
964964 (a -> Bool) -> t m a -> t m a
965−takeWhileEnd = undefined -- fromStreamD $ D.takeWhileEnd n $ toStreamD m
965+takeWhileLast = undefined -- fromStreamD $ D.takeWhileLast n $ toStreamD m
966966
967−-- | Like 'takeWhile' and 'takeWhileEnd' combined.
967+-- | Like 'takeWhile' and 'takeWhileLast' combined.
968968--
969969-- O(n) space, where n is the number elements taken from the end.
970970--
@@ -974,7 +974,7 @@ takeWhileAround :: -- (IsStream t, Monad m) =>
974974 (a -> Bool) -> t m a -> t m a
975975takeWhileAround = undefined -- fromStreamD $ D.takeWhileAround n $ toStreamD m
976976
977−-- | @takeByTime duration@ yields stream elements upto specified time
977+-- | @takeInterval duration@ yields stream elements upto specified time
978978-- @duration@. The duration starts when the stream is evaluated for the first
979979-- time, before the first element is yielded. The time duration is checked
980980-- before generating each element, if the duration has expired the stream
@@ -990,9 +990,9 @@ takeWhileAround = undefined -- fromStreamD $ D.takeWhileAround n $ toStreamD m
990990--
991991-- /Pre-release/
992992--
993−{-# INLINE takeByTime #-}
994−takeByTime ::(MonadIO m, IsStream t, TimeUnit64 d) => d -> t m a -> t m a
995−takeByTime d = fromStreamD . D.takeByTime d . toStreamD
993+{-# INLINE takeInterval #-}
994+takeInterval ::(MonadIO m, IsStream t, TimeUnit64 d) => d -> t m a -> t m a
995+takeInterval d = fromStreamD . D.takeByTime d . toStreamD
996996
997997-- | Drop elements in the stream as long as the predicate succeeds and then
998998-- take the rest of the stream.
@@ -1009,7 +1009,7 @@ dropWhile p m = fromStreamS $ S.dropWhile p $ toStreamS m
10091009dropWhileM :: (IsStream t, Monad m) => (a -> m Bool) -> t m a -> t m a
10101010dropWhileM p m = fromStreamD $ D.dropWhileM p $ toStreamD m
10111011
1012−-- | @dropByTime duration@ drops stream elements until specified @duration@ has
1012+-- | @dropInterval duration@ drops stream elements until specified @duration@ has
10131013-- passed. The duration begins when the stream is evaluated for the first
10141014-- time. The time duration is checked /after/ generating a stream element, the
10151015-- element is yielded if the duration has expired otherwise it is dropped.
@@ -1023,29 +1023,29 @@ dropWhileM p m = fromStreamD $ D.dropWhileM p $ toStreamD m
10231023--
10241024-- /Pre-release/
10251025--
1026−{-# INLINE dropByTime #-}
1027−dropByTime ::(MonadIO m, IsStream t, TimeUnit64 d) => d -> t m a -> t m a
1028−dropByTime d = fromStreamD . D.dropByTime d . toStreamD
1026+{-# INLINE dropInterval #-}
1027+dropInterval ::(MonadIO m, IsStream t, TimeUnit64 d) => d -> t m a -> t m a
1028+dropInterval d = fromStreamD . D.dropByTime d . toStreamD
10291029
10301030-- | Drop @n@ elements at the end of the stream.
10311031--
10321032-- O(n) space, where n is the number elements dropped.
10331033--
10341034-- /Unimplemented/
1035−{-# INLINE dropEnd #-}
1036−dropEnd :: -- (IsStream t, Monad m) =>
1035+{-# INLINE dropLast #-}
1036+dropLast :: -- (IsStream t, Monad m) =>
10371037 Int -> t m a -> t m a
1038−dropEnd = undefined -- fromStreamD $ D.dropEnd n $ toStreamD m
1038+dropLast = undefined -- fromStreamD $ D.dropLast n $ toStreamD m
10391039
10401040-- | Drop time interval @i@ seconds at the end of the stream.
10411041--
10421042-- O(n) space, where n is the number elements dropped.
10431043--
10441044-- /Unimplemented/
1045−{-# INLINE dropEndInterval #-}
1046−dropEndInterval :: -- (IsStream t, Monad m) =>
1045+{-# INLINE dropLastInterval #-}
1046+dropLastInterval :: -- (IsStream t, Monad m) =>
10471047 Int -> t m a -> t m a
1048−dropEndInterval = undefined
1048+dropLastInterval = undefined
10491049
10501050-- | Drop all consecutive elements at the end of the stream for which the
10511051-- predicate is true.
@@ -1053,12 +1053,12 @@ dropEndInterval = undefined
10531053-- O(n) space, where n is the number elements dropped.
10541054--
10551055-- /Unimplemented/
1056−{-# INLINE dropWhileEnd #-}
1057−dropWhileEnd :: -- (IsStream t, Monad m) =>
1056+{-# INLINE dropWhileLast #-}
1057+dropWhileLast :: -- (IsStream t, Monad m) =>
10581058 (a -> Bool) -> t m a -> t m a
1059−dropWhileEnd = undefined -- fromStreamD $ D.dropWhileEnd n $ toStreamD m
1059+dropWhileLast = undefined -- fromStreamD $ D.dropWhileLast n $ toStreamD m
10601060
1061−-- | Like 'dropWhile' and 'dropWhileEnd' combined.
1061+-- | Like 'dropWhile' and 'dropWhileLast' combined.
10621062--
10631063-- O(n) space, where n is the number elements dropped from the end.
10641064--