-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Conduit with a smaller core -- -- Please see the README on GitHub at -- https://github.com/ssadler/piped#readme @package piped @version 0.1.0.0 -- | The internal API and core datatypes of Pipe. module Piped.Internal -- | The Pipe datatype, that represents a stage in a pipeline with inputs -- of type i and outputs of type o. newtype Pipe i o m a Pipe :: (forall r. (Await i m r -> Yield o m r -> a -> m r) -> Await i m r -> Yield o m r -> m r) -> Pipe i o m a [unPipe] :: Pipe i o m a -> forall r. (Await i m r -> Yield o m r -> a -> m r) -> Await i m r -> Yield o m r -> m r -- | Await a value. Nothing indicates that there are no more values. await :: Monad m => Pipe i o m (Maybe i) -- | Yield a value to downstream. yield :: o -> Pipe i o m () -- | Run pipe to completion. runPipe :: Monad m => Pipe () Void m r -> m r -- | Push a value back into the incoming pipeline leftover :: i -> Pipe i o m () -- | The upstream continuation; holds a callback that provides a value. newtype Await i m a Await :: Await' i m a -> Await i m a [unAwait] :: Await i m a -> Await' i m a -- | The downstream continuation; holds a callback that accepts a value, -- plus a default return value in case there is no more input. data Yield i m a Yield :: m a -> Yield' i m a -> Yield i m a [terminate] :: Yield i m a -> m a [unYield] :: Yield i m a -> Yield' i m a -- | The type of an upstream continuation type Await' i m a = Yield i m a -> m a -- | The type of a downstream continuation type Yield' i m a = i -> Await i m a -> m a -- | Run an Await runAwait :: Await i m a -> m a -> Yield' i m a -> m a -- | Run a Yield runYield :: Yield i m a -> i -> Await' i m a -> m a -- | An Await that terminates when called. termLeft :: Await i m a -- | A Yield that terminates when called. termRight :: Yield i1 m a -> Yield i2 m a -- | A Void output voidRight :: Yield Void m a -- | Wrap an Await with a leftover value addLeftover :: i -> Await i m a -> Await i m a -- | Uninhabited data type data Void fix1 :: a -> ((a -> b) -> a -> b) -> b fix2 :: a -> b -> ((a -> b -> c) -> a -> b -> c) -> c instance GHC.Base.Monad m => GHC.Base.Functor (Piped.Internal.Pipe i o m) instance GHC.Base.Monad m => GHC.Base.Applicative (Piped.Internal.Pipe i o m) instance GHC.Base.Monad m => GHC.Base.Monad (Piped.Internal.Pipe i o m) instance Control.Monad.Trans.Class.MonadTrans (Piped.Internal.Pipe i o) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Piped.Internal.Pipe i o m) instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Piped.Internal.Pipe i o m) instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Piped.Internal.Pipe i o m) instance GHC.Base.Monad m => GHC.Base.Semigroup (Piped.Internal.Pipe i o m a) instance GHC.Base.Monad m => GHC.Base.Monoid (Piped.Internal.Pipe i o m ()) -- | Convenience methods, plus bracketPipe. module Piped.Extras -- | Yield all values from a foldable data structure such as a list. sourceList :: (Monad m, Foldable t) => t o -> Pipe () o m () -- | Return all input values as a list. sinkList :: Pipe i Void m [i] -- | Consume all values using given function awaitForever :: Monad m => (i -> Pipe i o m a) -> Pipe i o m () -- | Discard all input values sinkNull :: Monad m => Pipe i Void m () -- | Basically `await >>= maybe ...`, but avoids the conversion to a -- maybe type. awaitMaybe :: Pipe i o m a -> (i -> Pipe i o m a) -> Pipe i o m a -- | Act on a value, if there is no value then return (). awaitJust :: Monad m => (i -> Pipe i o m ()) -> Pipe i o m () -- | Yield the result of a monadic action. yieldM :: Monad m => Pipe i o m o -> Pipe i o m () -- | This is the same as bracketP from Conduit, however it's not -- specialised to MonadResource. bracketPipe :: Monad m => m b -> (b -> m ()) -> (b -> Pipe i o m a) -> Pipe i o m a -- | Pipe composition can be supply or demand driven, which refers to how -- the pipeline is initiated. Supply driven initiates the left side -- first. -- -- When a pipe terminates, one side must return a value. Unless the -- pipeline is run in resumable mode, the other sides may never -- "complete" in that they do not return a value. If they allocate -- resources, MonadResource or similar should be used to handle cleanup -- (see bracketPipe). -- -- Right hand termination works by indicating that no more values are -- available. -- -- In a mode where either side can return a value, no special termination -- logic is invoked, execution ends the first time a side returns. -- -- Left termination is not provided; since there is no way to indicate to -- the left side that the right has terminated, and potential solutions -- involve discarding values. However, the "either" modes are also -- suitable for left termination. module Piped.Compose -- | Demand driven; same as 'composeDemand (.|) :: Monad m => Pipe i e m () -> Pipe e o m b -> Pipe i o m b -- | Supply driven; same as 'composeSupplyEither (|.) :: Monad m => Pipe i e m a -> Pipe e o m a -> Pipe i o m a -- | The right side is run first, only the right side may return a value. composeDemand :: Monad m => Pipe i e m () -> Pipe e o m b -> Pipe i o m b -- | The right side is run first, either side may return a value. composeDemandEither :: Monad m => Pipe i e m a -> Pipe e o m a -> Pipe i o m a -- | The left side is run first, only the right side may return a value. composeSupply :: Monad m => Pipe i e m () -> Pipe e o m b -> Pipe i o m b -- | The left side is run first, either side may return a value. composeSupplyEither :: Monad m => Pipe i e m a -> Pipe e o m a -> Pipe i o m a module Piped -- | The Pipe datatype, that represents a stage in a pipeline with inputs -- of type i and outputs of type o. data Pipe i o m a -- | Await a value. Nothing indicates that there are no more values. await :: Monad m => Pipe i o m (Maybe i) -- | Yield a value to downstream. yield :: o -> Pipe i o m () -- | Demand driven; same as 'composeDemand (.|) :: Monad m => Pipe i e m () -> Pipe e o m b -> Pipe i o m b -- | Supply driven; same as 'composeSupplyEither (|.) :: Monad m => Pipe i e m a -> Pipe e o m a -> Pipe i o m a -- | Run pipe to completion. runPipe :: Monad m => Pipe () Void m r -> m r -- | Push a value back into the incoming pipeline leftover :: i -> Pipe i o m () -- | Consume all values using given function awaitForever :: Monad m => (i -> Pipe i o m a) -> Pipe i o m () -- | Basically `await >>= maybe ...`, but avoids the conversion to a -- maybe type. awaitMaybe :: Pipe i o m a -> (i -> Pipe i o m a) -> Pipe i o m a -- | Act on a value, if there is no value then return (). awaitJust :: Monad m => (i -> Pipe i o m ()) -> Pipe i o m () -- | Yield the result of a monadic action. yieldM :: Monad m => Pipe i o m o -> Pipe i o m () -- | Yield all values from a foldable data structure such as a list. sourceList :: (Monad m, Foldable t) => t o -> Pipe () o m () -- | Return all input values as a list. sinkList :: Pipe i Void m [i] -- | Discard all input values sinkNull :: Monad m => Pipe i Void m () -- | Uninhabited data type data Void -- | Basic functionality, closely mirroring the list / Foldable api from -- Prelude. -- -- This module should be imported qualified i.e. `import Piped.Prelude as -- P`. module Piped.Prelude -- | Yield only elements satisfying a predicate. filter :: Monad m => (i -> Bool) -> Pipe i i m () -- | Yield values while they satisfy a predicate, then return. takeWhile :: Monad m => (i -> Bool) -> Pipe i i m () -- | Drop values while they satisfy a predicate, then return. -- -- Note: this does not yield any values, and should be combined with -- (>>). dropWhile :: Monad m => (i -> Bool) -> Pipe i o m () -- | Equivalent to `map id`. identity :: Monad m => Pipe i i m () -- | map with an accumulator. scanl :: forall i o m. (o -> i -> o) -> o -> Pipe i o m () -- | Left fold over input values. foldl :: Monad m => (a -> i -> a) -> a -> Pipe i o m a -- | Drop n values. -- -- Note: This will not yield values and should be combined with -- >> drop :: Monad m => Int -> Pipe i o m () -- | Take n values. take :: Monad m => Int -> Pipe i i m () -- | Map a pure function over input values. map :: Monad m => (i -> o) -> Pipe i o m () -- | Map a monadic function over input values. mapM :: Monad m => (i -> m o) -> Pipe i o m () -- | Map a monadic function over input values but don't yield anything. mapM_ :: Monad m => (i -> m ()) -> Pipe i () m () -- | Skip the first value tail :: Monad m => Pipe i i m () -- | Return the last value. last :: Monad m => Pipe i o m (Maybe i) -- | Zip two pipes together. zip :: Monad m => Pipe () o m () -> Pipe () o' m () -> Pipe () (o, o') m () -- | Zip two pipes together with a pure function. zipWith :: Monad m => (o -> o' -> a) -> Pipe () o m () -> Pipe () o' m () -> Pipe () a m () -- | Concatenate foldable inputs to a single stream of outputs. concat :: (Foldable t, Monad m) => Pipe (t i) i m () module Piped.Resume -- | Create a resumable source from a Pipe createResumableSource :: Monad m => Pipe () o m a -> ResumableSource o m a b -- | Create a resumable sink from a Pipe createResumableSink :: Monad m => Pipe i Void m b -> ResumableSink i m a b -- | Run a resumable source runResumableSource :: Monad m => ResumableSource i m a b -> Pipe i Void m b -> m (ResumableResult i m a b) -- | Run a resumable sink runResumableSink :: Monad m => Pipe () o m a -> ResumableSink o m a b -> m (ResumableResult o m a b) -- | A source that may be resumed newtype ResumableSource o m a b ResumableSource :: Await o m (ResumableResult o m a b) -> ResumableSource o m a b -- | A sink that may be resumed newtype ResumableSink i m a b ResumableSink :: Yield i m (ResumableResult i m a b) -> ResumableSink i m a b -- | Either a resumable source or sink, plus the result of the pipe that -- finished. data ResumableResult e m a b ResumeSource :: ResumableSource e m a b -> b -> ResumableResult e m a b ResumeSink :: ResumableSink e m a b -> a -> ResumableResult e m a b