packages feed

streaming 0.1.0.11 → 0.1.0.12

raw patch · 4 files changed

+60/−32 lines, 4 files

Files

Streaming.hs view
@@ -13,8 +13,8 @@    replicates,    repeats,    repeatsM,+   delay,    wrap,-   step,        -- * Transforming streams    maps,
Streaming/Internal.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE RankNTypes, StandaloneDeriving,DeriveDataTypeable, BangPatterns #-} {-# LANGUAGE UndecidableInstances, CPP #-} -- for show, data instances-{-#LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} module Streaming.Internal (     -- * The free monad transformer     -- $stream@@ -12,8 +11,8 @@     , replicates     , repeats     , repeatsM+    , delay     , wrap-    , step     , layer          -- * Eliminating a stream@@ -24,7 +23,7 @@     , destroy      , destroyWith     -    -- * Inspecting a stream step by step+    -- * Inspecting a stream wrap by wrap     , inspect           -- * Transforming streams@@ -105,9 +104,15 @@   fmap f = loop where     loop stream = case stream of       Return r -> Return (f r)-      Delay m  -> Delay (liftM loop m)+      Delay m  -> Delay (do {stream' <- m; return (loop stream')})       Step f   -> Step (fmap loop f)   {-# INLINABLE fmap #-}+  a <$ stream0 = loop stream0 where+    loop stream = case stream of+      Return r -> Return a+      Delay m  -> Delay (do {stream' <- m; return (loop stream')})+      Step f    -> Step (fmap loop f)+  {-# INLINABLE (<$) #-}        instance (Functor f, Monad m) => Monad (Stream f m) where   return = Return@@ -117,20 +122,33 @@       Return _ -> stream2       Delay m  -> Delay (liftM loop m)       Step f   -> Step (fmap loop f)    -  {-# INLINABLE (>>) #-}                              +  {-# INLINABLE (>>) #-}   stream >>= f = loop stream where     loop stream0 = case stream0 of       Step f -> Step (fmap loop f)       Delay m      -> Delay (liftM loop m)       Return r      -> f r   {-# INLINABLE (>>=) #-}                              -+  fail = lift . fail+   instance (Functor f, Monad m) => Applicative (Stream f m) where   pure = Return   {-# INLINE pure #-}   streamf <*> streamx = do {f <- streamf; x <- streamx; return (f x)}      {-# INLINABLE (<*>) #-}    -  +  stra0 *> strb = loop stra0 where+    loop stra = case stra of+      Return _ -> strb+      Delay m  -> Delay (do {stra' <- m ; return (stra' *> strb)})+      Step fstr -> Step (fmap (*> strb) fstr)+  {-# INLINABLE (*>) #-}    +  stra <* strb0 = loop strb0 where+    loop strb = case strb of+      Return _ -> stra+      Delay m  -> Delay (do {strb' <- m ; return (stra <* strb')})+      Step fstr -> Step (fmap (stra <*) fstr)+  {-# INLINABLE (<*) #-}    +     instance Functor f => MonadTrans (Stream f) where   lift = Delay . liftM Return   {-# INLINE lift #-}@@ -173,10 +191,10 @@ destroy   :: (Functor f, Monad m) =>      Stream f m r -> (f b -> b) -> (m b -> b) -> (r -> b) -> b-destroy stream0 construct wrap done = loop (unexposed stream0) where+destroy stream0 construct delay done = loop (unexposed stream0) where   loop stream = case stream of     Return r -> done r-    Delay m  -> wrap (liftM loop m)+    Delay m  -> delay (liftM loop m)     Step fs  -> construct (fmap loop fs) {-# INLINABLE destroy #-} @@ -191,26 +209,26 @@ >>> :t destroyWith (join . lift) return (Monad m, Monad (t m), Functor f, MonadTrans t) =>      (f (t m a) -> t m a) -> Stream f m a -> t m a  -- iterTM->>> :t destroyWith wrap return+>>> :t destroyWith delay return (Monad m, Functor f, Functor f1) =>      (f (Stream f1 m r) -> Stream f1 m r) -> Stream f m r -> Stream f1 m r->>> :t destroyWith wrap return (step . lazily)+>>> :t destroyWith delay return (wrap . lazily) Monad m =>       Stream (Of a) m r -> Stream ((,) a) m r->>> :t destroyWith wrap return (step . strictly)+>>> :t destroyWith delay return (wrap . strictly) Monad m =>       Stream ((,) a) m r -> Stream (Of a) m r->>> :t destroyWith Data.ByteString.Streaming.wrap return  +>>> :t destroyWith Data.ByteString.Streaming.delay return   (Monad m, Functor f) =>      (f (ByteString m r) -> ByteString m r) -> Stream f m r -> ByteString m r->>> :t destroyWith Data.ByteString.Streaming.wrap return (\(a:>b) -> consChunk a b) +>>> :t destroyWith Data.ByteString.Streaming.delay return (\(a:>b) -> consChunk a b)  Monad m =>       Stream (Of B.ByteString) m r -> ByteString m r -- fromChunks -} destroyWith   :: (Functor f, Monad m) =>      (m b -> b) -> (r -> b) -> (f b -> b) -> Stream f m r -> b-destroyWith wrap done construct stream  = destroy stream construct wrap done+destroyWith delay done construct stream  = destroy stream construct delay done  -- | Reflect a church-encoded stream; cp. @GHC.Exts.build@ construct@@ -505,15 +523,15 @@ --     See Atkey "Reasoning about Stream Processing with Effects"  -destroyExposed stream0 construct wrap done = loop stream0 where+destroyExposed stream0 construct delay done = loop stream0 where   loop stream = case stream of     Return r -> done r-    Delay m  -> wrap (liftM loop m)+    Delay m  -> delay (liftM loop m)     Step fs  -> construct (fmap loop fs) {-# INLINABLE destroyExposed #-}  -{-| This is akin to the @observe@ of @Pipes.Internal@ . It rewraps the layering+{-| This is akin to the @observe@ of @Pipes.Internal@ . It redelays the layering     in instances of @Stream f m r@ so that it replicates that of      @FreeT@.  @@ -528,11 +546,11 @@   -wrap :: (Monad m, Functor f ) => m (Stream f m r) -> Stream f m r-wrap = Delay+delay :: (Monad m, Functor f ) => m (Stream f m r) -> Stream f m r+delay = Delay -step :: (Monad m, Functor f ) => f (Stream f m r) -> Stream f m r-step = Step+wrap :: (Monad m, Functor f ) => f (Stream f m r) -> Stream f m r+wrap = Step   zipsWith :: (Monad m, Functor h) 
Streaming/Prelude.hs view
@@ -558,7 +558,7 @@ -} foldM'     :: Monad m-    => (x -> a -> m x) -> m x -> (x -> m b) -> Stream (Of a) m r -> m (Of b r)+    => (x -> a -> m x) -> m x -> (x -> m b) -> Stream (Of a) m r ->m (Of b r) foldM' step begin done str = do     x0 <- begin     loop str x0
streaming.cabal view
@@ -1,24 +1,28 @@ name:                streaming-version:             0.1.0.11+version:             0.1.0.12 cabal-version:       >=1.10 build-type:          Simple synopsis:            A free monad transformer optimized for streaming applications.                       description:         `Stream` can be used wherever `FreeT` is used. The compiler's                      standard range of optimizations work better for operations -                     written in terms of `Stream`. See the examples in @Streaming.Prelude@ -                     for a sense of how simple the library is to use and think about.+                     written in terms of `Stream`. @FreeT f m r@ / @Stream f m r@+                     is of course extremely general, and many functor-general combinators+                     are exported by the general module @Streaming@.                       . -                     @Streaming.Prelude@ closely follows -                     @Pipes.Prelude@, but cleverly /omits the pipes/. It is focused -                     on employment with base functors which generate-                     effectful sequences. These appear elsewhere under titles like+                     See the examples in @Streaming.Prelude@ for a sense of how +                     simple the library is to use and think about. +                     That module is focused on employment with such base functors +                     (readings of the @f@ in @Stream f m r@) that express +                     different forms of effectful sequences. Some of these appear +                     elsewhere under titles like                      .                      > pipes:      Producer a m r, Producer a m (Producer a m r), FreeT (Producer a m) m r                      > io-streams: InputStream a, Generator a r                      > conduit:    Source m a, ConduitM () o m r                      .-                     and the like.+                     and the like. @Streaming.Prelude@ closely follows +                     @Pipes.Prelude@, but cleverly /omits the pipes/.                       .                      Interoperation with                       <http://hackage.haskell.org/package/pipes pipes>@@ -39,6 +43,12 @@                      > Conduit.unfoldM Streaming.uncons    :: Stream (Of a) m ()  -> Source m a                      .                      These conversions should never be more expensive than a single @>->@ or @=$=@.+                     .+                     With a much more general level, we also of course have interopetion with +                     <http://hackage.haskell.org/package/free free>:+                     .+                     Free.iterTM  Stream.wrap              :: FreeT f m a -> Stream f m a+                     Stream.iterTM Free.wrap               :: Stream f m a -> FreeT f m a                       .                      See the companion package <https://hackage.haskell.org/package/streaming-bytestring streaming-bytestring>                      For some simple examples, see