Module

Run.Streaming

Package
purescript-run-streaming
Repository
natefaubion/purescript-run-streaming

This module defines primitives for bidirectional streams analagous to the Haskell Pipes library. Namely, streams may be either push or pull and can propagate information both upstream and downstream.

#Step Source

data Step i o a

Constructors

Instances

#STEP Source

type STEP i o = FProxy (Step i o)

#YIELD Source

type YIELD a = STEP Unit a

#AWAIT Source

type AWAIT a = STEP a Unit

#REQUEST Source

type REQUEST req res = STEP res req

#RESPOND Source

type RESPOND req res = STEP req res

#_yield Source

_yield :: SProxy "yield"

#_await Source

_await :: SProxy "await"

#yield Source

yield :: forall r o. o -> Run (Producer o r) Unit

Yields a value to be consumed downstream.

#await Source

await :: forall r i. Run (Consumer i r) i

Awaits a value upstream.

#request Source

request :: forall r res req. req -> Run (Client req res r) res

Issues a request and awaits a response.

#respond Source

respond :: forall r res req. res -> Run (Server req res r) req

Yields a response and waits for a request.

#Resume Source

data Resume r a i o

Constructors

Instances

#Producer Source

type Producer o r = (yield :: YIELD o | r)

Producers yield values of type o using effects r.

#Consumer Source

type Consumer i r = (await :: AWAIT i | r)

Consumers await values of type i using effects r.

#Transformer Source

type Transformer i o r = (await :: AWAIT i, yield :: YIELD o | r)

Transformers await values i and yield values o using effects r.

#Client Source

type Client req res r = (await :: REQUEST req res | r)

Clients issue requests req and await responses res using effects r.

#Server Source

type Server req res r = (yield :: RESPOND req res | r)

Servers reply to requests req with responses res using effects r.

#Pipe Source

type Pipe req res req' res' r = (await :: REQUEST req res, yield :: RESPOND req' res' | r)

A full bidirectional Pipe acts as an upstream Client and a downstream Server.

#runStep Source

runStep :: forall a r2 r1 o i sym. Cons sym (FProxy (Step i o)) r1 r2 => IsSymbol sym => SProxy sym -> Run r2 a -> Run r1 (Resume r1 a i o)

#runYield Source

runYield :: forall o i a r. Run (Server i o r) a -> Run r (Resume r a i o)

#runAwait Source

runAwait :: forall o i a r. Run (Client i o r) a -> Run r (Resume r a o i)

#interleave Source

interleave :: forall o i a r. (o -> Run r (Resume r a o i)) -> Resume r a i o -> Run r a

Subsitutes the outputs of the second argument with the continuation of the first argument, and vice versa, interleaving the two.

#substitute Source

substitute :: forall o i a r. (o -> Run r i) -> Resume r a i o -> Run r a

Substitutes the outputs of the second argument with the effects of the first argument, feeding the result back in to the stream.