Module Foundation defines the pipe computations and their basic building blocks.
- class Monad m => ParallelizableMonad m where
- parallelize :: m a -> m b -> m (a, b)
- data Pipe context m r
- data Source context x
- data Sink context x
- pipe :: forall context x m r1 r2. Monad m => Producer context m x r1 -> Consumer context m x r2 -> Pipe context m (r1, r2)
- pipeD :: forall c x m r1 r2. Monad m => String -> Producer c m x r1 -> Consumer c m x r2 -> Pipe c m (r1, r2)
- pipeP :: forall c x m r1 r2. ParallelizableMonad m => Producer c m x r1 -> Consumer c m x r2 -> Pipe c m (r1, r2)
- get :: forall context x m r. (Monad m, Typeable x) => Source context x -> Pipe context m (Maybe x)
- getSuccess :: forall context x m. (Monad m, Typeable x) => Source context x -> (x -> Pipe context m ()) -> Pipe context m ()
- get' :: forall context x m r. (Monad m, Typeable x) => Source context x -> Pipe context m x
- canPut :: forall context x m r. (Monad m, Typeable x) => Sink context x -> Pipe context m Bool
- put :: forall context x m r. (Monad m, Typeable x) => Sink context x -> x -> Pipe context m Bool
- liftPipe :: forall context m r. Monad m => m r -> Pipe context m r
- runPipes :: forall m r. Monad m => (forall context. Pipe context m r) -> m r
- cond :: a -> a -> Bool -> a
- whenNull :: forall a m. Monad m => m [a] -> [a] -> m [a]
- pour :: forall c x m. (Monad m, Typeable x) => Source c x -> Sink c x -> Pipe c m ()
- pourMap :: forall c x y m. (Monad m, Typeable x, Typeable y) => (x -> y) -> Source c x -> Sink c y -> Pipe c m ()
- pourMapMaybe :: forall c x y m. (Monad m, Typeable x, Typeable y) => (x -> Maybe y) -> Source c x -> Sink c y -> Pipe c m ()
- tee :: (Monad m, Typeable x) => Source c x -> Sink c x -> Sink c x -> Pipe c m ()
- getList :: forall x c m. (Monad m, Typeable x) => Source c x -> Pipe c m [x]
- putList :: forall x c m. (Monad m, Typeable x) => [x] -> Sink c x -> Pipe c m [x]
- putQueue :: forall c m x. (Monad m, Typeable x) => Seq x -> Sink c x -> Pipe c m [x]
- consumeAndSuppress :: forall x c m. (Monad m, Typeable x) => Source c x -> Pipe c m ()
Classes
class Monad m => ParallelizableMonad m whereSource
parallelize :: m a -> m b -> m (a, b)Source
Types
Pipe
represents the type of monadic computations that can be split into co-routining computations using function
pipe
. The context type parameter delimits the scope of the computation.
Monad m => Monad (Pipe context m) | |
ParallelizableMonad m => ParallelizableMonad (Pipe context m) |
Flow-control functions
pipe :: forall context x m r1 r2. Monad m => Producer context m x r1 -> Consumer context m x r2 -> Pipe context m (r1, r2)Source
pipeD :: forall c x m r1 r2. Monad m => String -> Producer c m x r1 -> Consumer c m x r2 -> Pipe c m (r1, r2)Source
pipeP :: forall c x m r1 r2. ParallelizableMonad m => Producer c m x r1 -> Consumer c m x r2 -> Pipe c m (r1, r2)Source
get :: forall context x m r. (Monad m, Typeable x) => Source context x -> Pipe context m (Maybe x)Source
get' :: forall context x m r. (Monad m, Typeable x) => Source context x -> Pipe context m xSource
Function get'
assumes that the argument source is not empty and returns the value the source yields. If the
source is empty, the function throws an error.
canPut :: forall context x m r. (Monad m, Typeable x) => Sink context x -> Pipe context m BoolSource
put :: forall context x m r. (Monad m, Typeable x) => Sink context x -> x -> Pipe context m BoolSource
runPipes :: forall m r. Monad m => (forall context. Pipe context m r) -> m rSource
Function runPipes
runs the given computation involving pipes and returns the final result.
The context argument ensures that no suspended computation can escape its scope.
Utility functions
cond :: a -> a -> Bool -> aSource
A utility function wrapping if-then-else, useful for handling monadic truth values
whenNull :: forall a m. Monad m => m [a] -> [a] -> m [a]Source
A utility function, useful for handling monadic list values where empty list means success
pour :: forall c x m. (Monad m, Typeable x) => Source c x -> Sink c x -> Pipe c m ()Source
pour
copies all data from the source argument into the sink argument, as long as there is anything to copy
and the sink accepts it.
pourMap :: forall c x y m. (Monad m, Typeable x, Typeable y) => (x -> y) -> Source c x -> Sink c y -> Pipe c m ()Source
pourMapMaybe :: forall c x y m. (Monad m, Typeable x, Typeable y) => (x -> Maybe y) -> Source c x -> Sink c y -> Pipe c m ()Source
pourMapMaybe
is to pourMap
like Data.Maybe.mapMaybe
is to Data.List.Map
.
getList :: forall x c m. (Monad m, Typeable x) => Source c x -> Pipe c m [x]Source
getList
returns the list of all values generated by the source.
putList :: forall x c m. (Monad m, Typeable x) => [x] -> Sink c x -> Pipe c m [x]Source
putList
puts entire list into its sink argument, as long as the sink accepts it. The remainder that wasn't
accepted by the sink is the result value.
consumeAndSuppress :: forall x c m. (Monad m, Typeable x) => Source c x -> Pipe c m ()Source
consumeAndSuppress
consumes the entire source ignoring the values it generates.