on master help sign in
Add Since: 0.8.0 annotations to new functions.
commit16dfa5638ad7454509214f255be3a0ae0a8bf609 authorPranay Sashank <pranaysashank@composewell.com> dateTue 30 Mar 2021, 12:43 (6 years ago) parent7a1463d
3 files changed+51−18
src/Streamly/Internal/Data/Stream/Async.hs+1−2 src/Streamly/Internal/Data/Unfold.hs+39−8 src/Streamly/Internal/Data/Unfold/Type.hs+11−8
src/Streamly/Internal/Data/Stream/Async.hs+1−2
@@ -515,7 +515,6 @@ mkAsyncD m = D.Stream step Nothing
515515 D.Skip s -> D.Skip (Just $ D.Stream step1 s)
516516 D.Stop -> D.Stop
517517
518−-- /Since: 0.8.0 ("Streamly.Prelude")/
519518--
520519-- This is slightly faster than the CPS version above
521520--
@@ -525,7 +524,7 @@ mkAsyncD m = D.Stream step Nothing
525524-- kicked off again to evaluate the remaining stream when there is space in the
526525-- buffer. The consumer consumes the stream lazily from the buffer.
527526--
528−-- /Pre-release/
527+-- /Since: 0.8.0/
529528--
530529{-# INLINE_NORMAL mkAsync #-}
531530mkAsync :: (K.IsStream t, MonadAsync m) => t m a -> t m a
src/Streamly/Internal/Data/Unfold.hs+39−8
@@ -266,7 +266,7 @@ import Prelude
266266-- lmapM f = Unfold.many (Unfold.functionM f)
267267-- @
268268--
269−-- /Pre-release/
269+-- /Since: 0.8.0/
270270{-# INLINE_NORMAL lmapM #-}
271271lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
272272lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
@@ -387,6 +387,11 @@ fold (Fold fstep initial extract) (Unfold ustep inject) a = do
387387 Skip s -> go SPEC fs s
388388 Stop -> extract fs
389389
390+-- | Apply a monadic function to each element of the stream and replace it
391+-- with the output of the resulting action.
392+--
393+-- /Since: 0.8.0/
394+--
390395{-# INLINE_NORMAL mapM #-}
391396mapM :: Monad m => (b -> m c) -> Unfold m a b -> Unfold m a c
392397mapM f (Unfold ustep uinject) = Unfold step uinject
@@ -449,7 +454,8 @@ fromStreamK = Unfold step return
449454-- | Convert a stream into an 'Unfold'. Note that a stream converted to an
450455-- 'Unfold' may not be as efficient as an 'Unfold' in some situations.
451456--
452−-- /Pre-release/
457+-- /Since: 0.8.0/
458+--
453459{-# INLINE_NORMAL fromStream #-}
454460fromStream :: (K.IsStream t, Monad m) => Unfold m (t m a) a
455461fromStream = lmap K.toStream fromStreamK
@@ -491,6 +497,9 @@ consM action unf = Unfold step inject
491497 Stop -> return Stop
492498
493499-- | Convert a list of pure values to a 'Stream'
500+--
501+-- /Since: 0.8.0/
502+--
494503{-# INLINE_LATE fromList #-}
495504fromList :: Monad m => Unfold m [a] a
496505fromList = Unfold step inject
@@ -501,6 +510,9 @@ fromList = Unfold step inject
501510 step [] = return Stop
502511
503512-- | Convert a list of monadic values to a 'Stream'
513+--
514+-- /Since: 0.8.0/
515+--
504516{-# INLINE_LATE fromListM #-}
505517fromListM :: Monad m => Unfold m [m a] a
506518fromListM = Unfold step inject
@@ -516,7 +528,7 @@ fromListM = Unfold step inject
516528
517529-- | Generates a stream replicating the seed @n@ times.
518530--
519−-- /Pre-release/
531+-- /Since: 0.8.0/
520532--
521533{-# INLINE replicateM #-}
522534replicateM :: Monad m => Int -> Unfold m (m a) a
@@ -536,7 +548,7 @@ replicateM n = Unfold step inject
536548
537549-- | Generates an infinite stream repeating the seed.
538550--
539−-- /Pre-release/
551+-- /Since: 0.8.0/
540552--
541553{-# INLINE repeatM #-}
542554repeatM :: Monad m => Unfold m (m a) a
@@ -548,7 +560,7 @@ repeatM = Unfold step return
548560-- | Generates an infinite stream starting with the given seed and applying the
549561-- given function repeatedly.
550562--
551−-- /Pre-release/
563+-- /Since: 0.8.0/
552564--
553565{-# INLINE iterateM #-}
554566iterateM :: Monad m => (a -> m a) -> Unfold m (m a) a
@@ -586,6 +598,8 @@ fromIndicesM gen = Unfold step return
586598-- >>> Unfold.fold Fold.toList u [1..100]
587599-- [1,2]
588600--
601+-- /Since: 0.8.0/
602+--
589603{-# INLINE_NORMAL take #-}
590604take :: Monad m => Int -> Unfold m a b -> Unfold m a b
591605take n (Unfold step1 inject1) = Unfold step inject
@@ -602,6 +616,10 @@ take n (Unfold step1 inject1) = Unfold step inject
602616 Stop -> Stop
603617 step (_, _) = return Stop
604618
619+-- | Same as 'takeWhile' but with a monadic predicate.
620+--
621+-- /Since: 0.8.0/
622+--
605623{-# INLINE_NORMAL takeWhileM #-}
606624takeWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
607625takeWhileM f (Unfold step1 inject1) = Unfold step inject1
@@ -616,10 +634,19 @@ takeWhileM f (Unfold step1 inject1) = Unfold step inject1
616634 Skip s -> return $ Skip s
617635 Stop -> return Stop
618636
637+-- | End the stream generated by the 'Unfold' as soon as the predicate fails
638+-- on an element.
639+--
640+-- /Since: 0.8.0/
641+--
619642{-# INLINE takeWhile #-}
620643takeWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
621644takeWhile f = takeWhileM (return . f)
622645
646+-- | Same as 'filter' but with a monadic predicate.
647+--
648+-- /Since: 0.8.0/
649+--
623650{-# INLINE_NORMAL filterM #-}
624651filterM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
625652filterM f (Unfold step1 inject1) = Unfold step inject1
@@ -634,13 +661,17 @@ filterM f (Unfold step1 inject1) = Unfold step inject1
634661 Skip s -> return $ Skip s
635662 Stop -> return Stop
636663
664+-- | Include only those elements that pass a predicate.
665+--
666+-- /Since: 0.8.0/
667+--
637668{-# INLINE filter #-}
638669filter :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
639670filter f = filterM (return . f)
640671
641672-- | @drop n unf@ drops @n@ elements from the stream generated by @unf@.
642673--
643−-- /Pre-release/
674+-- /Since: 0.8.0/
644675--
645676{-# INLINE_NORMAL drop #-}
646677drop :: Monad m => Int -> Unfold m a b -> Unfold m a b
@@ -672,7 +703,7 @@ drop n (Unfold step inject) = Unfold step' inject'
672703-- | @dropWhileM f unf@ drops elements from the stream generated by @unf@ while
673704-- the condition holds true. The condition function @f@ is /monadic/ in nature.
674705--
675−-- /Pre-release/
706+-- /Since: 0.8.0/
676707--
677708{-# INLINE_NORMAL dropWhileM #-}
678709dropWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
@@ -706,7 +737,7 @@ dropWhileM f (Unfold step inject) = Unfold step' inject'
706737
707738-- | Similar to 'dropWhileM' but with a pure condition function.
708739--
709−-- /Pre-release/
740+-- /Since: 0.8.0/
710741--
711742{-# INLINE dropWhile #-}
712743dropWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
src/Streamly/Internal/Data/Unfold/Type.hs+11−8
@@ -107,7 +107,7 @@ mkUnfoldrM step = Unfold step pure
107107-- The step function returns the next element in the stream and the next seed
108108-- value. When it is done it returns 'Nothing' and the stream ends.
109109--
110−-- /Pre-release/
110+-- /Since: 0.8.0/
111111--
112112{-# INLINE unfoldrM #-}
113113unfoldrM :: Applicative m => (a -> m (Maybe (b, a))) -> Unfold m a b
@@ -129,7 +129,7 @@ unfoldrM next = Unfold step pure
129129-- >>> Unfold.fold Fold.toList (Unfold.unfoldr f) [1,2,3]
130130-- [1,2,3]
131131--
132−-- /Pre-release/
132+-- /Since: 0.8.0/
133133--
134134{-# INLINE unfoldr #-}
135135unfoldr :: Applicative m => (a -> Maybe (b, a)) -> Unfold m a b
@@ -149,7 +149,7 @@ unfoldr step = unfoldrM (pure . step)
149149-- lmap f = Unfold.many (Unfold.function f)
150150-- @
151151--
152−-- /Pre-release/
152+-- /Since: 0.8.0/
153153{-# INLINE_NORMAL lmap #-}
154154lmap :: (a -> c) -> Unfold m c b -> Unfold m a b
155155lmap f (Unfold ustep uinject) = Unfold ustep (uinject Prelude.. f)
@@ -264,7 +264,8 @@ crossWithM f (Unfold step1 inject1) (Unfold step2 inject2) = Unfold step inject
264264-- >>> Unfold.fold Fold.toList u ([1,2,3], [4,5,6])
265265-- [(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)]
266266--
267−-- /Pre-release/
267+-- /Since: 0.8.0/
268+--
268269{-# INLINE crossWith #-}
269270crossWith :: Monad m =>
270271 (b -> c -> d) -> Unfold m a b -> Unfold m a c -> Unfold m a d
@@ -398,7 +399,8 @@ instance Monad m => Monad (Unfold m a) where
398399-- | Lift a monadic function into an unfold. The unfold generates a singleton
399400-- stream.
400401--
401−-- /Pre-release/
402+-- /Since: 0.8.0/
403+
402404{-# INLINE functionM #-}
403405functionM :: Applicative m => (a -> m b) -> Unfold m a b
404406functionM f = Unfold step inject
@@ -416,7 +418,8 @@ functionM f = Unfold step inject
416418--
417419-- > function f = functionM $ return . f
418420--
419−-- /Pre-release/
421+-- /Since: 0.8.0/
422+
420423{-# INLINE function #-}
421424function :: Applicative m => (a -> b) -> Unfold m a b
422425function f = functionM $ pure Prelude.. f
@@ -437,7 +440,7 @@ data ConcatState s1 s2 = ConcatOuter s1 | ConcatInner s1 s2
437440-- | Apply the second unfold to each output element of the first unfold and
438441-- flatten the output in a single stream.
439442--
440−-- /Pre-release/
443+-- /Since: 0.8.0/
441444--
442445{-# INLINE_NORMAL many #-}
443446many :: Monad m => Unfold m a b -> Unfold m b c -> Unfold m a c
@@ -530,7 +533,7 @@ zipWithM f (Unfold step1 inject1) (Unfold step2 inject2) = Unfold step inject
530533--
531534-- > zipWith f = zipWithM (\a b -> return $ f a b)
532535--
533−-- /Pre-release/
536+-- /Since: 0.8.0/
534537--
535538{-# INLINE zipWith #-}
536539zipWith :: Monad m