on master help sign in
Rename Unfold.yield, yieldM to fromPure, fromEffect.
f24ddc0Pranay Sashank
benchmark/Streamly/Benchmark/Data/Unfold.hs+9−9
@@ -196,7 +196,7 @@ _identity _ start = drainGeneration UF.identity start
196{-# INLINE _const #-}
196{-# INLINE _const #-}
197_const :: Monad m => Int -> Int -> m ()
197_const :: Monad m => Int -> Int -> m ()
198_const size start =
198_const size start =
199− drainGeneration (UF.take size (UF.yieldM (return start))) undefined
199+ drainGeneration (UF.take size (UF.fromEffect (return start))) undefined
200
200
201{-# INLINE unfoldrM #-}
201{-# INLINE unfoldrM #-}
202unfoldrM :: Monad m => Int -> Int -> m ()
202unfoldrM :: Monad m => Int -> Int -> m ()
@@ -450,7 +450,7 @@ toNull value start =
450 -}
450 -}
451 u = src `UF.bind` \x ->
451 u = src `UF.bind` \x ->
452 src `UF.bind` \y ->
452 src `UF.bind` \y ->
453− UF.yield (x + y)
453+ UF.fromPure (x + y)
454 in UF.fold FL.drain u start
454 in UF.fold FL.drain u start
455
455
456
456
@@ -468,7 +468,7 @@ toNull3 value start =
468 -}
468 -}
469 u = src `UF.bind` \x ->
469 u = src `UF.bind` \x ->
470 src `UF.bind` \y ->
470 src `UF.bind` \y ->
471− UF.yield (x + y)
471+ UF.fromPure (x + y)
472 in UF.fold FL.drain u start
472 in UF.fold FL.drain u start
473
473
474{-# INLINE toList #-}
474{-# INLINE toList #-}
@@ -484,7 +484,7 @@ toList value start = do
484 -}
484 -}
485 u = src `UF.bind` \x ->
485 u = src `UF.bind` \x ->
486 src `UF.bind` \y ->
486 src `UF.bind` \y ->
487− UF.yield (x + y)
487+ UF.fromPure (x + y)
488 in UF.fold FL.toList u start
488 in UF.fold FL.toList u start
489
489
490{-# INLINE toListSome #-}
490{-# INLINE toListSome #-}
@@ -500,7 +500,7 @@ toListSome value start = do
500 -}
500 -}
501 u = src `UF.bind` \x ->
501 u = src `UF.bind` \x ->
502 src `UF.bind` \y ->
502 src `UF.bind` \y ->
503− UF.yield (x + y)
503+ UF.fromPure (x + y)
504 in UF.fold FL.toList (UF.take 1000 u) start
504 in UF.fold FL.toList (UF.take 1000 u) start
505
505
506{-# INLINE filterAllOut #-}
506{-# INLINE filterAllOut #-}
@@ -517,7 +517,7 @@ filterAllOut value start = do
517 src `UF.bind` \y ->
517 src `UF.bind` \y ->
518 let s = x + y
518 let s = x + y
519 in if s < 0
519 in if s < 0
520− then UF.yield s
520+ then UF.fromPure s
521 else UF.nilM (return . const ())
521 else UF.nilM (return . const ())
522 in UF.fold FL.drain u start
522 in UF.fold FL.drain u start
523
523
@@ -535,7 +535,7 @@ filterAllIn value start = do
535 src `UF.bind` \y ->
535 src `UF.bind` \y ->
536 let s = x + y
536 let s = x + y
537 in if s > 0
537 in if s > 0
538− then UF.yield s
538+ then UF.fromPure s
539 else UF.nilM (return . const ())
539 else UF.nilM (return . const ())
540 in UF.fold FL.drain u start
540 in UF.fold FL.drain u start
541
541
@@ -553,7 +553,7 @@ filterSome value start = do
553 src `UF.bind` \y ->
553 src `UF.bind` \y ->
554 let s = x + y
554 let s = x + y
555 in if s > 1100000
555 in if s > 1100000
556− then UF.yield s
556+ then UF.fromPure s
557 else UF.nilM (return . const ())
557 else UF.nilM (return . const ())
558 in UF.fold FL.drain u start
558 in UF.fold FL.drain u start
559
559
@@ -572,7 +572,7 @@ breakAfterSome value start =
572 let s = x + y
572 let s = x + y
573 in if s > 1100000
573 in if s > 1100000
574 then error "break"
574 then error "break"
575− else UF.yield s
575+ else UF.fromPure s
576 in do
576 in do
577 (_ :: Either ErrorCall ()) <- try $ UF.fold FL.drain u start
577 (_ :: Either ErrorCall ()) <- try $ UF.fold FL.drain u start
578 return ()
578 return ()
src/Streamly/Internal/Data/Pipe.hs+1−1
@@ -1845,7 +1845,7 @@ classifySessionsBy tick timeout reset (Fold step initial extract) str =
1845 let (r, mp') = Map.updateLookupWithKey (\_ _ -> Nothing) key mp
1845 let (r, mp') = Map.updateLookupWithKey (\_ _ -> Nothing) key mp
1846 Tuple' _ acc <- accumulate r
1846 Tuple' _ acc <- accumulate r
1847 res <- extract acc
1847 res <- extract acc
1848− return $ Tuple4' evTime hp mp' (S.yield (key, res))
1848+ return $ Tuple4' evTime hp mp' (S.fromPure (key, res))
1849 else do
1849 else do
1850 let r = Map.lookup key mp
1850 let r = Map.lookup key mp
1851 acc <- accumulate r
1851 acc <- accumulate r
src/Streamly/Internal/Data/Unfold.hs+2−2
@@ -129,8 +129,8 @@ module Streamly.Internal.Data.Unfold
129 , consM
129 , consM
130
130
131 -- ** From Values
131 -- ** From Values
132− , yieldM
132+ , fromEffect
133− , yield
133+ , fromPure
134
134
135 -- ** Generators
135 -- ** Generators
136 -- | Generate a monadic stream from a seed.
136 -- | Generate a monadic stream from a seed.
src/Streamly/Internal/Data/Unfold/Type.hs+10−10
@@ -25,8 +25,8 @@ module Streamly.Internal.Data.Unfold.Type
25 , identity
25 , identity
26
26
27 -- * From Values
27 -- * From Values
28− , yieldM
28+ , fromEffect
29− , yield
29+ , fromPure
30
30
31 -- * Transformations
31 -- * Transformations
32 , lmap
32 , lmap
@@ -183,9 +183,9 @@ instance Functor m => Functor (Unfold m a) where
183-- supplied monadic action.
183-- supplied monadic action.
184--
184--
185-- /Pre-release/
185-- /Pre-release/
186−{-# INLINE yieldM #-}
186+{-# INLINE fromEffect #-}
187−yieldM :: Applicative m => m b -> Unfold m a b
187+fromEffect :: Applicative m => m b -> Unfold m a b
188−yieldM m = Unfold step inject
188+fromEffect m = Unfold step inject
189
189
190 where
190 where
191
191
@@ -194,13 +194,13 @@ yieldM m = Unfold step inject
194 step False = (`Yield` True) <$> m
194 step False = (`Yield` True) <$> m
195 step True = pure Stop
195 step True = pure Stop
196
196
197−-- | Discards the unfold input and always returns the argument of 'yield'.
197+-- | Discards the unfold input and always returns the argument of 'fromPure'.
198--
198--
199−-- > yield = yieldM . pure
199+-- > fromPure = fromEffect . pure
200--
200--
201-- /Pre-release/
201-- /Pre-release/
202−yield :: Applicative m => b -> Unfold m a b
202+fromPure :: Applicative m => b -> Unfold m a b
203−yield = yieldM Prelude.. pure
203+fromPure = fromEffect Prelude.. pure
204
204
205-- | Outer product discarding the first element.
205-- | Outer product discarding the first element.
206--
206--
@@ -300,7 +300,7 @@ apply u1 u2 = fmap (\(a, b) -> a b) (cross u1 u2)
300--
300--
301instance Monad m => Applicative (Unfold m a) where
301instance Monad m => Applicative (Unfold m a) where
302 {-# INLINE pure #-}
302 {-# INLINE pure #-}
303− pure = yield
303+ pure = fromPure
304
304
305 {-# INLINE (<*>) #-}
305 {-# INLINE (<*>) #-}
306 (<*>) = apply
306 (<*>) = apply
test/Streamly/Test/Data/Unfold.hs+1−1
@@ -141,7 +141,7 @@ functionM =
141
141
142const :: Bool
142const :: Bool
143const =
143const =
144− let unf = UF.yieldM (modify (+ 1) >> get)
144+ let unf = UF.fromEffect (modify (+ 1) >> get)
145 in testUnfoldMD unf (0 :: Int) 0 1 [1]
145 in testUnfoldMD unf (0 :: Int) 0 1 [1]
146
146
147unfoldrM :: Property
147unfoldrM :: Property