on master help sign in
Rename Parser.yield, yieldM to fromPure, fromEffect.
commit7d9256e283113f1169dd30cc50257fca103d273c authorPranay Sashank <pranaysashank@composewell.com> dateSat 29 May 2021, 23:28 (5 years ago) parent90be387
10 files changed+73−73
README.md+1−1 src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+2−2 src/Streamly/Internal/Data/Binary/Decode.hs+1−1 src/Streamly/Internal/Data/Parser.hs+12−12 src/Streamly/Internal/Data/Parser/ParserD.hs+2−2 src/Streamly/Internal/Data/Parser/ParserD/Type.hs+11−11 src/Streamly/Internal/Data/Parser/ParserK/Type.hs+11−11 src/Streamly/Internal/FileSystem/Event/Linux.hs+3−3 test/Streamly/Test/Data/Parser.hs+14−14 test/Streamly/Test/Data/Parser/ParserD.hs+16−16
README.md+1−1
@@ -388,7 +388,7 @@ listDir dir =
388388main :: IO ()
389389main = do
390390 hSetBuffering stdout LineBuffering
391− let start = Stream.yield (Left ".")
391+ let start = Stream.fromPure (Left ".")
392392 Stream.iterateMapLeftsWith Stream.ahead listDir start
393393 & Stream.mapM_ print
394394```
src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+2−2
@@ -206,7 +206,7 @@ rmapM f (Fold p) = Fold $ ParserD.rmapM f p
206206--
207207{-# INLINE fromPure #-}
208208fromPure :: Monad m => b -> Fold m a b
209−fromPure = Fold . ParserD.yield
209+fromPure = Fold . ParserD.fromPure
210210
211211-- | A fold that always yields the result of an effectful action without
212212-- consuming any input.
@@ -215,7 +215,7 @@ fromPure = Fold . ParserD.yield
215215--
216216{-# INLINE fromEffect #-}
217217fromEffect :: Monad m => m b -> Fold m a b
218−fromEffect = Fold . ParserD.yieldM
218+fromEffect = Fold . ParserD.fromEffect
219219
220220-- | Applies two folds sequentially on the input stream and combines their
221221-- results using the supplied function.
src/Streamly/Internal/Data/Binary/Decode.hs+1−1
@@ -47,7 +47,7 @@ import qualified Streamly.Internal.Data.Parser.ParserK.Type as PRK
4747--
4848{-# INLINE unit #-}
4949unit :: MonadCatch m => Parser m Word8 ()
50−unit = eqWord8 0 *> PR.yield ()
50+unit = eqWord8 0 *> PR.fromPure ()
5151
5252{-# INLINE word8ToBool #-}
5353word8ToBool :: Word8 -> Either String Bool
src/Streamly/Internal/Data/Parser.hs+12−12
@@ -54,8 +54,8 @@ module Streamly.Internal.Data.Parser
5454 -- First order parsers
5555 -- * Accumulators
5656 , fromFold
57− , yield
58− , yieldM
57+ , fromPure
58+ , fromEffect
5959 , die
6060 , dieM
6161
@@ -231,28 +231,28 @@ fromFold = K.toParserK . D.fromFold
231231-- Terminating but not failing folds
232232-------------------------------------------------------------------------------
233233--
234−-- This is the dual of stream "yield".
234+-- This is the dual of stream "fromPure".
235235--
236236-- | A parser that always yields a pure value without consuming any input.
237237--
238238-- /Pre-release/
239239--
240−{-# INLINE [3] yield #-}
241−yield :: MonadCatch m => b -> Parser m a b
242−yield = K.toParserK . D.yield
243−{-# RULES "yield fallback to CPS" [2]
244− forall a. K.toParserK (D.yield a) = K.yield a #-}
240+{-# INLINE [3] fromPure #-}
241+fromPure :: MonadCatch m => b -> Parser m a b
242+fromPure = K.toParserK . D.fromPure
243+{-# RULES "fromPure fallback to CPS" [2]
244+ forall a. K.toParserK (D.fromPure a) = K.fromPure a #-}
245245
246−-- This is the dual of stream "yieldM".
246+-- This is the dual of stream "fromEffect".
247247--
248248-- | A parser that always yields the result of an effectful action without
249249-- consuming any input.
250250--
251251-- /Pre-release/
252252--
253−{-# INLINE yieldM #-}
254−yieldM :: MonadCatch m => m b -> Parser m a b
255−yieldM = K.yieldM -- K.toParserK . D.yieldM
253+{-# INLINE fromEffect #-}
254+fromEffect :: MonadCatch m => m b -> Parser m a b
255+fromEffect = K.fromEffect -- K.toParserK . D.fromEffect
256256
257257-- This is the dual of "nil".
258258--
src/Streamly/Internal/Data/Parser/ParserD.hs+2−2
@@ -21,8 +21,8 @@ module Streamly.Internal.Data.Parser.ParserD
2121 -- First order parsers
2222 -- * Accumulators
2323 , fromFold
24− , yield
25− , yieldM
24+ , fromPure
25+ , fromEffect
2626 , die
2727 , dieM
2828
src/Streamly/Internal/Data/Parser/ParserD/Type.hs+11−11
@@ -117,8 +117,8 @@ module Streamly.Internal.Data.Parser.ParserD.Type
117117 , ParseError (..)
118118 , rmapM
119119
120− , yield
121− , yieldM
120+ , fromPure
121+ , fromEffect
122122 , serialWith
123123 , split_
124124
@@ -339,21 +339,21 @@ rmapM f (Parser step initial extract) = Parser step1 initial1 (extract >=> f)
339339 IError err -> return $ IError err
340340 step1 s a = step s a >>= mapMStep f
341341
342−-- | See 'Streamly.Internal.Data.Parser.yield'.
342+-- | See 'Streamly.Internal.Data.Parser.fromPure'.
343343--
344344-- /Pre-release/
345345--
346−{-# INLINE_NORMAL yield #-}
347−yield :: Monad m => b -> Parser m a b
348−yield b = Parser undefined (pure $ IDone b) undefined
346+{-# INLINE_NORMAL fromPure #-}
347+fromPure :: Monad m => b -> Parser m a b
348+fromPure b = Parser undefined (pure $ IDone b) undefined
349349
350−-- | See 'Streamly.Internal.Data.Parser.yieldM'.
350+-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
351351--
352352-- /Pre-release/
353353--
354−{-# INLINE yieldM #-}
355−yieldM :: Monad m => m b -> Parser m a b
356−yieldM b = Parser undefined (IDone <$> b) undefined
354+{-# INLINE fromEffect #-}
355+fromEffect :: Monad m => m b -> Parser m a b
356+fromEffect b = Parser undefined (IDone <$> b) undefined
357357
358358-------------------------------------------------------------------------------
359359-- Sequential applicative
@@ -608,7 +608,7 @@ noErrorUnsafeSplit_ (Parser stepL initialL extractL) (Parser stepR initialR extr
608608-- | 'Applicative' form of 'serialWith'.
609609instance MonadThrow m => Applicative (Parser m a) where
610610 {-# INLINE pure #-}
611− pure = yield
611+ pure = fromPure
612612
613613 {-# INLINE (<*>) #-}
614614 (<*>) = serialWith id
src/Streamly/Internal/Data/Parser/ParserK/Type.hs+11−11
@@ -21,8 +21,8 @@
2121module Streamly.Internal.Data.Parser.ParserK.Type
2222 (
2323 Parser (..)
24− , yield
25− , yieldM
24+ , fromPure
25+ , fromEffect
2626 , die
2727
2828 -- * Conversion
@@ -279,23 +279,23 @@ instance Functor m => Functor (Parser m a) where
279279-- Sequential applicative
280280-------------------------------------------------------------------------------
281281
282−-- This is the dual of stream "yield".
282+-- This is the dual of stream "fromPure".
283283--
284284-- | A parser that always yields a pure value without consuming any input.
285285--
286286-- /Pre-release/
287287--
288−{-# INLINE yield #-}
289−yield :: b -> Parser m a b
290−yield b = MkParser $ \lo st yieldk -> yieldk st (Done lo b)
288+{-# INLINE fromPure #-}
289+fromPure :: b -> Parser m a b
290+fromPure b = MkParser $ \lo st yieldk -> yieldk st (Done lo b)
291291
292−-- | See 'Streamly.Internal.Data.Parser.yieldM'.
292+-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
293293--
294294-- /Pre-release/
295295--
296−{-# INLINE yieldM #-}
297−yieldM :: Monad m => m b -> Parser m a b
298−yieldM eff = MkParser $ \lo st yieldk -> eff >>= \b -> yieldk st (Done lo b)
296+{-# INLINE fromEffect #-}
297+fromEffect :: Monad m => m b -> Parser m a b
298+fromEffect eff = MkParser $ \lo st yieldk -> eff >>= \b -> yieldk st (Done lo b)
299299
300300-- | 'Applicative' form of 'Streamly.Internal.Data.Parser.serialWith'. Note that
301301-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.serialWith'
@@ -303,7 +303,7 @@ yieldM eff = MkParser $ \lo st yieldk -> eff >>= \b -> yieldk st (Done lo b)
303303--
304304instance Monad m => Applicative (Parser m a) where
305305 {-# INLINE pure #-}
306− pure = yield
306+ pure = fromPure
307307
308308 {-# INLINE (<*>) #-}
309309 (<*>) = ap
src/Streamly/Internal/FileSystem/Event/Linux.hs+3−3
@@ -774,7 +774,7 @@ readOneEvent :: Config -> Watch -> Parser IO Word8 Event
774774readOneEvent cfg wt@(Watch _ wdMap) = do
775775 let headerLen = (sizeOf (undefined :: CInt)) + 12
776776 arr <- PR.takeEQ headerLen (A.writeN headerLen)
777− (ewd, eflags, cookie, pathLen) <- PR.yieldM $ A.asPtr arr readHeader
777+ (ewd, eflags, cookie, pathLen) <- PR.fromEffect $ A.asPtr arr readHeader
778778 -- XXX need the "initial" in parsers to return a step type so that "take 0"
779779 -- can return without an input. otherwise if pathLen is 0 we will keep
780780 -- waiting to read one more char before we return this event.
@@ -792,7 +792,7 @@ readOneEvent cfg wt@(Watch _ wdMap) = do
792792 when (remaining /= 0) $ PR.takeEQ remaining FL.drain
793793 return pth
794794 else return $ A.fromList []
795− wdm <- PR.yieldM $ readIORef wdMap
795+ wdm <- PR.fromEffect $ readIORef wdMap
796796 let (root, sub) =
797797 case Map.lookup (fromIntegral ewd) wdm of
798798 Just pair -> pair
@@ -805,7 +805,7 @@ readOneEvent cfg wt@(Watch _ wdMap) = do
805805 -- Check for "ISDIR" first because it is less likely
806806 isDirCreate = eflags .&. iN_ISDIR /= 0 && eflags .&. iN_CREATE /= 0
807807 when (watchRec cfg && isDirCreate)
808− $ PR.yieldM $ addToWatch cfg wt root sub1
808+ $ PR.fromEffect $ addToWatch cfg wt root sub1
809809 -- XXX Handle IN_DELETE, IN_DELETE_SELF, IN_MOVE_SELF, IN_MOVED_FROM,
810810 -- IN_MOVED_TO
811811 -- What if a large dir tree gets moved in to our hierarchy? Do we get a
test/Streamly/Test/Data/Parser.hs+14−14
@@ -61,17 +61,17 @@ fromFold =
6161 Right is_equal -> is_equal
6262 Left _ -> False
6363
64−yield :: Property
65−yield =
64+fromPure :: Property
65+fromPure =
6666 forAll (chooseInt (min_value, max_value)) $ \x ->
67− case S.parse (P.yield x) (S.fromList [1 :: Int]) of
67+ case S.parse (P.fromPure x) (S.fromList [1 :: Int]) of
6868 Right r -> r == x
6969 Left _ -> False
7070
71−yieldM :: Property
72−yieldM =
71+fromEffect :: Property
72+fromEffect =
7373 forAll (chooseInt (min_value, max_value)) $ \x ->
74− case S.parse (P.yieldM $ return x) (S.fromList [1 :: Int]) of
74+ case S.parse (P.fromEffect $ return x) (S.fromList [1 :: Int]) of
7575 Right r -> r == x
7676 Left _ -> False
7777
@@ -418,13 +418,13 @@ wordBy =
418418
419419-- splitWithFailLeft :: Property
420420-- splitWithFailLeft =
421−-- property (case S.parse (P.serialWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
421+-- property (case S.parse (P.serialWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
422422-- Right _ -> False
423423-- Left _ -> True)
424424
425425-- splitWithFailRight :: Property
426426-- splitWithFailRight =
427−-- property (case S.parse (P.serialWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
427+-- property (case S.parse (P.serialWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
428428-- Right _ -> False
429429-- Left _ -> True)
430430
@@ -447,13 +447,13 @@ wordBy =
447447
448448-- teeWithFailLeft :: Property
449449-- teeWithFailLeft =
450−-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
450+-- property (case S.parse (P.teeWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
451451-- Right _ -> False
452452-- Left _ -> True)
453453
454454-- teeWithFailRight :: Property
455455-- teeWithFailRight =
456−-- property (case S.parse (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
456+-- property (case S.parse (P.teeWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
457457-- Right _ -> False
458458-- Left _ -> True)
459459
@@ -489,13 +489,13 @@ wordBy =
489489
490490-- shortestFailLeft :: Property
491491-- shortestFailLeft =
492−-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
492+-- property (case S.parse (P.shortest (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
493493-- Right r -> r == 1
494494-- Left _ -> False)
495495
496496-- shortestFailRight :: Property
497497-- shortestFailRight =
498−-- property (case S.parse (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
498+-- property (case S.parse (P.shortest (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
499499-- Right r -> r == 1
500500-- Left _ -> False)
501501
@@ -705,8 +705,8 @@ main =
705705
706706 describe "test for accumulator" $ do
707707 prop "P.fromFold FL.sum = FL.sum" fromFold
708− prop "yield value provided" yield
709− prop "yield monadic value provided" yieldM
708+ prop "fromPure value provided" fromPure
709+ prop "fromPure monadic value provided" fromEffect
710710 prop "fail err = Left (SomeException (ParseError err))" parserFail
711711 prop "always fail" die
712712 prop "always fail but monadic" dieM
test/Streamly/Test/Data/Parser/ParserD.hs+16−16
@@ -64,17 +64,17 @@ fromFold =
6464 Right is_equal -> is_equal
6565 Left _ -> False
6666
67−yield :: Property
68−yield =
67+fromPure :: Property
68+fromPure =
6969 forAll (chooseInt (min_value, max_value)) $ \x ->
70− case S.parseD (P.yield x) (S.fromList [1 :: Int]) of
70+ case S.parseD (P.fromPure x) (S.fromList [1 :: Int]) of
7171 Right r -> r == x
7272 Left _ -> False
7373
74−yieldM :: Property
75−yieldM =
74+fromEffect :: Property
75+fromEffect =
7676 forAll (chooseInt (min_value, max_value)) $ \x ->
77− case S.parseD (P.yieldM $ return x) (S.fromList [1 :: Int]) of
77+ case S.parseD (P.fromEffect $ return x) (S.fromList [1 :: Int]) of
7878 Right r -> r == x
7979 Left _ -> False
8080
@@ -396,13 +396,13 @@ serialWith =
396396
397397splitWithFailLeft :: Property
398398splitWithFailLeft =
399− property (case S.parseD (P.serialWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
399+ property (case S.parseD (P.serialWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
400400 Right _ -> False
401401 Left _ -> True)
402402
403403splitWithFailRight :: Property
404404splitWithFailRight =
405− property (case S.parseD (P.serialWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
405+ property (case S.parseD (P.serialWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
406406 Right _ -> False
407407 Left _ -> True)
408408
@@ -425,13 +425,13 @@ teeWithPass =
425425
426426teeWithFailLeft :: Property
427427teeWithFailLeft =
428− property (case S.parseD (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
428+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
429429 Right _ -> False
430430 Left _ -> True)
431431
432432teeWithFailRight :: Property
433433teeWithFailRight =
434− property (case S.parseD (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
434+ property (case S.parseD (P.teeWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
435435 Right _ -> False
436436 Left _ -> True)
437437
@@ -456,13 +456,13 @@ shortestPass =
456456
457457shortestPassLeft :: Property
458458shortestPassLeft =
459− property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
459+ property (case S.parseD (P.shortest (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
460460 Right r -> r == 1
461461 Left _ -> False)
462462
463463shortestPassRight :: Property
464464shortestPassRight =
465− property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
465+ property (case S.parseD (P.shortest (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
466466 Right r -> r == 1
467467 Left _ -> False)
468468
@@ -490,13 +490,13 @@ longestPass =
490490
491491longestPassLeft :: Property
492492longestPassLeft =
493− property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
493+ property (case S.parseD (P.shortest (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
494494 Right r -> r == 1
495495 Left _ -> False)
496496
497497longestPassRight :: Property
498498longestPassRight =
499− property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
499+ property (case S.parseD (P.shortest (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
500500 Right r -> r == 1
501501 Left _ -> False)
502502
@@ -723,8 +723,8 @@ main =
723723
724724 describe "test for accumulator" $ do
725725 prop "P.fromFold FL.sum = FL.sum" fromFold
726− prop "yield value provided" yield
727− prop "yield monadic value provided" yieldM
726+ prop "fromPure value provided" fromPure
727+ prop "fromPure monadic value provided" fromEffect
728728 prop "always fail" die
729729 prop "always fail but monadic" dieM
730730