packages feed

pipes-fluid 0.5.0.2 → 0.5.0.3

raw patch · 4 files changed

+40/−9 lines, 4 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Pipes.Fluid.Impulse: instance (GHC.Base.Alternative m, GHC.Base.Monad m, Data.Semigroup.Semigroup a) => Data.Semigroup.Semigroup (Pipes.Fluid.Impulse.Impulse m a)
+ Pipes.Fluid.Impulse: instance (GHC.Base.Alternative m, GHC.Base.Monad m, Data.Semigroup.Semigroup a) => GHC.Base.Monoid (Pipes.Fluid.Impulse.Impulse m a)
+ Pipes.Fluid.ImpulseIO: instance (Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO m, Data.Constraint.Forall.Forall (Control.Concurrent.Async.Lifted.Safe.Pure m), Data.Semigroup.Semigroup a) => Data.Semigroup.Semigroup (Pipes.Fluid.ImpulseIO.ImpulseIO m a)
+ Pipes.Fluid.ImpulseIO: instance (Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO m, Data.Constraint.Forall.Forall (Control.Concurrent.Async.Lifted.Safe.Pure m), Data.Semigroup.Semigroup a) => GHC.Base.Monoid (Pipes.Fluid.ImpulseIO.ImpulseIO m a)
+ Pipes.Fluid.Merge: discrete' :: Merged x x -> NonEmpty x
+ Pipes.Fluid.Merge: mergeDiscrete :: (Semigroup x, Merge f, Functor f) => f x -> f x -> f x
+ Pipes.Fluid.Merge: mergeDiscrete' :: (Merge f, Functor f) => f x -> f x -> f (NonEmpty x)

Files

pipes-fluid.cabal view
@@ -1,5 +1,5 @@ name:                pipes-fluid-version:             0.5.0.2+version:             0.5.0.3 synopsis:            Reactively combines Producers so that a value is yielded as soon as possible. description:         Please see README.md homepage:            https://github.com/louispan/pipes-fluid#readme
src/Pipes/Fluid/Impulse.hs view
@@ -16,6 +16,7 @@ import Control.Applicative import Control.Lens import Control.Monad.Trans.Class+import Data.Semigroup import Data.These import qualified Pipes as P import Pipes.Fluid.Merge@@ -28,6 +29,13 @@     }  makeWrapped ''Impulse++instance  (Alternative m, Monad m, Semigroup a) => Semigroup (Impulse m a) where+    (<>) = mergeDiscrete++instance  (Alternative m, Monad m, Semigroup a) => Monoid (Impulse m a) where+    mempty = Impulse $ pure ()+    mappend = mergeDiscrete  instance Monad m =>          Functor (Impulse m) where
src/Pipes/Fluid/ImpulseIO.hs view
@@ -22,6 +22,7 @@ import Control.Monad.Trans.Class import Control.Monad.Trans.Control import Data.Constraint.Forall (Forall)+import Data.Semigroup import Data.These import qualified Pipes as P import Pipes.Fluid.Merge@@ -38,6 +39,13 @@     }  makeWrapped ''ImpulseIO++instance  (MonadBaseControl IO m, Forall (A.Pure m), Semigroup a) => Semigroup (ImpulseIO m a) where+    (<>) = mergeDiscrete++instance  (MonadBaseControl IO m, Forall (A.Pure m), Semigroup a) => Monoid (ImpulseIO m a) where+    mempty = ImpulseIO $ pure ()+    mappend = mergeDiscrete  instance Monad m => Functor (ImpulseIO m) where   fmap f (ImpulseIO as) = ImpulseIO $ as P.>-> PP.map f
src/Pipes/Fluid/Merge.hs view
@@ -4,6 +4,8 @@  import qualified GHC.Generics as G import Data.Semigroup+import Data.Foldable+import qualified Data.List.NonEmpty as NE  -- | Differentiates whether a value from either or both producers. -- In the case of one producer, additional identify if the other producer is live or dead.@@ -98,12 +100,25 @@ discreteBoth (Coupled FromBoth x y) = Just (x, y) discreteBoth _ = Nothing --- | Keep only the values originated from both, replacing other yields with Nothing.--- This is useful when React is based on STM, since filtering with Producer STM results in--- larger STM transactions which may result in blocking.+-- | Keep only the "new" values+discrete' :: Merged x x -> NE.NonEmpty x+discrete' (Coupled FromBoth x y) = x  NE.:| [y]+discrete' (Coupled (FromRight _) _ y) = y NE.:| []+discrete' (Coupled (FromLeft _) x _) = x NE.:| []+discrete' (RightOnly _ y) = y NE.:| []+discrete' (LeftOnly _ x) = x  NE.:| []++-- | Keep only the "new" values (using semigroup <> when both values were active) discrete :: Semigroup x => Merged x x -> x-discrete (Coupled FromBoth x y) = x <> y-discrete (Coupled (FromRight _) _ y) = y-discrete (Coupled (FromLeft _) x _) = x-discrete (RightOnly _ y) = y-discrete (LeftOnly _ x) = x+discrete = nonEmptyFoldl1' . discrete'+    where+      nonEmptyFoldl1' :: Semigroup b => NE.NonEmpty b -> b+      nonEmptyFoldl1' (x  NE.:| xs) = foldl' (<>) x xs++-- | merge two producers of the same type together.+mergeDiscrete' :: (Merge f, Functor f) => f x -> f x -> f (NE.NonEmpty x)+mergeDiscrete' x y = discrete' <$> (x `merge` y)++-- | merge two producers of the same type together (using semigroup <> when both values were active)+mergeDiscrete :: (Semigroup x, Merge f, Functor f) => f x -> f x -> f x+mergeDiscrete x y = discrete <$> (x `merge` y)