on master help sign in
Rename tapCount to parTapCount
commit92b4094d46432553e28d45c267ce22f29e1cd75b authorHarendra Kumar <harendra@composewell.com> dateSat 22 Apr 2023, 20:00 (4 years ago) parent0e14d71
3 files changed+28−22
src/Streamly/Data/Stream/Concurrent.hs+3 src/Streamly/Internal/Data/Stream/Concurrent.hs+24−21 src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+1−1
src/Streamly/Data/Stream/Concurrent.hs+3
@@ -98,6 +98,9 @@ module Streamly.Data.Stream.Concurrent
9898 , parConcatIterate
9999
100100 -- *** Observation
101+ , parTapCount
102+
103+ -- ** Deprecated
101104 , tapCount
102105 )
103106where
src/Streamly/Internal/Data/Stream/Concurrent.hs+24−21
@@ -92,7 +92,7 @@ module Streamly.Internal.Data.Stream.Concurrent
9292
9393 -- ** Reactive
9494 , fromCallback
95− , tapCountD
95+ , parTapCount
9696 , tapCount
9797 )
9898where
@@ -726,14 +726,30 @@ fromCallback setCallback = Stream.concatEffect $ do
726726 setCallback callback
727727 return stream
728728
729−{-# INLINE_NORMAL tapCountD #-}
730−tapCountD
729+-- | @parTapCount predicate fold stream@ taps the count of those elements in
730+-- the stream that pass the @predicate@. The resulting count stream is sent to
731+-- a @fold@ running concurrently in another thread.
732+--
733+-- For example, to print the count of elements processed every second:
734+--
735+-- >>> rate = Stream.rollingMap2 (flip (-)) . Stream.delayPost 1
736+-- >>> report = Stream.fold (Fold.drainMapM print) . rate
737+-- >>> tap = Stream.parTapCount (const True) report
738+-- >>> go = Stream.fold Fold.drain $ tap $ Stream.enumerateFrom 0
739+--
740+-- Note: This may not work correctly on 32-bit machines because of Int
741+-- overflow.
742+--
743+-- /Pre-release/
744+--
745+{-# INLINE_NORMAL parTapCount #-}
746+parTapCount
731747 :: MonadAsync m
732748 => (a -> Bool)
733749 -> (D.Stream m Int -> m b)
734750 -> D.Stream m a
735751 -> D.Stream m a
736−tapCountD predicate fld (D.Stream step state) = D.Stream step' Nothing
752+parTapCount predicate fld (D.Stream step state) = D.Stream step' Nothing
737753 where
738754
739755 {-# INLINE_LATE step' #-}
@@ -759,22 +775,9 @@ tapCountD predicate fld (D.Stream step state) = D.Stream step' Nothing
759775 liftIO $ killThread tid
760776 return Stop
761777
762−-- | @tapCount predicate fold stream@ taps the count of those elements in the
763−-- stream that pass the @predicate@. The resulting count stream is sent to
764−-- another thread which folds it using @fold@.
765−--
766−-- For example, to print the count of elements processed every second:
767−--
768−-- >>> rate = Stream.rollingMap2 (flip (-)) . Stream.delayPost 1
769−-- >>> report = Stream.fold (Fold.drainMapM print) . rate
770−-- >>> tap = Stream.tapCount (const True) report
771−-- >>> go = Stream.fold Fold.drain $ tap $ Stream.enumerateFrom 0
772−--
773−-- Note: This may not work correctly on 32-bit machines because of Int
774−-- overflow.
775−--
776−-- /Pre-release/
777−--
778+-- Deprecate in a major release.
779+-- {-# DEPRECATED tapCount "Please use parTapCount instead." #-}
780+-- | Same as 'parTapCount'. Deprecated.
778781{-# INLINE tapCount #-}
779782tapCount ::
780783 (MonadAsync m)
@@ -782,4 +785,4 @@ tapCount ::
782785 -> (Stream m Int -> m b)
783786 -> Stream m a
784787 -> Stream m a
785−tapCount = tapCountD
788+tapCount = parTapCount
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+1−1
@@ -583,7 +583,7 @@ pollCounts ::
583583 -> t m a
584584pollCounts predicate f xs =
585585 fromStreamD
586− $ Concur.tapCountD predicate (f . fromStreamD)
586+ $ Concur.parTapCount predicate (f . fromStreamD)
587587 $ toStreamD xs
588588
589589-- | Apply a monadic function to each element flowing through the stream and