on master help sign in
Inline liftA2 in folds and parsers
commit179d7e601193547caa06878b9ebf3db47a74472f authorHarendra Kumar <harendra@composewell.com> dateMon 1 Mar 2021, 20:50 (6 years ago) parent4f556e8
3 files changed+17−2
src/Streamly/Internal/Data/Fold/Types.hs+5 src/Streamly/Internal/Data/Parser/ParserD/Types.hs+6−1 src/Streamly/Internal/Data/Parser/ParserK/Types.hs+6−1
src/Streamly/Internal/Data/Fold/Types.hs+5
@@ -591,6 +591,11 @@ instance Monad m => Applicative (Fold m a) where
591591 {-# INLINE (<*>) #-}
592592 (<*>) = teeWith ($)
593593
594+#if MIN_VERSION_base(4,10,0)
595+ {-# INLINE liftA2 #-}
596+ liftA2 f x = (<*>) (fmap f x)
597+#endif
598+
594599-- | @teeWith k f1 f2@ distributes its input to both @f1@ and @f2@ until both
595600-- of them terminate and combines their output using @k@.
596601--
src/Streamly/Internal/Data/Parser/ParserD/Types.hs+6−1
@@ -132,7 +132,7 @@ module Streamly.Internal.Data.Parser.ParserD.Types
132132 )
133133where
134134
135−import Control.Applicative (Alternative(..))
135+import Control.Applicative (Alternative(..), liftA2)
136136import Control.Exception (assert, Exception(..))
137137import Control.Monad (MonadPlus(..))
138138import Control.Monad.Catch (MonadCatch, try, throwM, MonadThrow)
@@ -524,6 +524,11 @@ instance MonadThrow m => Applicative (Parser m a) where
524524 {-# INLINE (*>) #-}
525525 (*>) = split_
526526
527+#if MIN_VERSION_base(4,10,0)
528+ {-# INLINE liftA2 #-}
529+ liftA2 f x = (<*>) (fmap f x)
530+#endif
531+
527532-------------------------------------------------------------------------------
528533-- Sequential Alternative
529534-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Parser/ParserK/Types.hs+6−1
@@ -31,7 +31,7 @@ module Streamly.Internal.Data.Parser.ParserK.Types
3131 )
3232where
3333
34−import Control.Applicative (Alternative(..))
34+import Control.Applicative (Alternative(..), liftA2)
3535import Control.Exception (assert, Exception(..))
3636import Control.Monad (MonadPlus(..), ap)
3737import Control.Monad.Catch (MonadCatch, MonadThrow(..), try)
@@ -319,6 +319,11 @@ instance Monad m => Applicative (Parser m a) where
319319 yield1 s (Error e) = yieldk s (Error e)
320320 in runParser m1 lo st yield1
321321
322+#if MIN_VERSION_base(4,10,0)
323+ {-# INLINE liftA2 #-}
324+ liftA2 f x = (<*>) (fmap f x)
325+#endif
326+
322327-------------------------------------------------------------------------------
323328-- Monad
324329-------------------------------------------------------------------------------