LanguageExt.Pipes

LanguageExt.Pipes Concurrent Conduit

Contents

record Conduit <A, B> (Sink<A> Sink, Source<B> Source) Source #

Represents a channel. A channel has:

  • An Sink: a queue of values that are its input.
  • An Source: a stream of values that are its output.

Both sides of the Conduit can be manipulated:

The Sink is a Cofunctor and can be mapped using Contramap, this transforms values before they get to the channel.

The Source is a Monad, so you can Map, Bind, Apply, in the usual way to map values on their way out. They manipulate values as they leave the channel.

Source values can be both merged (using + or Combine) and 'chosen' using |orChoose`.

Incoming Sink values can be split and passed to multiple Sink channels using (using + or `Combine)

ToProducer and ToConsumer allows the Conduit components to be used in composed pipe effects.

Parameters

type A

Input value type

type B

Output value type

param Sink

Sink

param Source

Source

Methods

method IO<Unit> Post (A value) Source #

Post a value to the Sink

Raises Errors.NoSpaceInSink if the Sink is full or closed.

Parameters

param value

Value to post

returns

IO computation that represents the posting

method IO<B> Read () Source #

Read value from the Source

Raises a Errors.SourceChannelClosed if the channel is closed or empty

Parameters

returns

First available value from the channel

method IO<Unit> Complete () Source #

Complete and close the Sink

method IO<Unit> Fail (Error Error) Source #

Complete and close the Sink with an Error

method Conduit<A, C> Map <C> (Func<B, C> f) Source #

Functor map

method Conduit<A, C> Bind <C> (Func<B, Source<C>> f) Source #

Monad bind

method Conduit<A, C> ApplyBack <C> (Source<Func<B, C>> ff) Source #

Applicative apply

method Conduit<X, B> Contramap <X> (Func<X, A> f) Source #

Contravariant functor map

method ConsumerT<A, M, Unit> ToConsumerT <M> () Source #

where M : Monad<M>

Convert the Sink to a ConsumerT pipe component

Parameters

type M

Monad to lift (must support IO)

returns

ConsumerT

method Consumer<RT, A, Unit> ToConsumer <RT> () Source #

Convert the Sink to a Consumer pipe component

Parameters

returns

Consumer

method ProducerT<B, M, Unit> ToProducerT <M> () Source #

where M : Monad<M>

Convert Source to a ProducerT pipe component

Parameters

type M

Monad to lift (must support IO)

returns

ProducerT

method Producer<RT, B, Unit> ToProducer <RT> () Source #

Convert Source to a Producer pipe component

Parameters

returns

Producer

method Conduit<A, B> Combine (Sink<A> rhs) Source #

Combine two Sinkes: lhs and rhs into a single Sink that takes incoming values and then posts the to the lhs and rhs Sinkes.

method Conduit<X, B> Combine <X, C> (Func<X, (A Left, C Right)> f, Sink<C> rhs) Source #

Combine two Sinkes: lhs and rhs into a single Sink that takes incoming values, maps them to an (A, B) tuple, and the posts the first and second elements to the lhs and rhs Sinkes.

method Conduit<A, B> Combine (Source<B> rhs) Source #

Combine two Sourcees into a single Source. The value streams are both merged into a new stream. Values are yielded as they become available.

Parameters

param rhs

Right hand side

returns

Merged stream of values

method Conduit<A, B> Choose (Source<B> rhs) Source #

Choose a value from the first Source to successfully yield

Parameters

param rhs
returns

Value from this Source if there are any available, if not, from rhs. If rhs is also empty then Errors.SourceChannelClosed is raised

Operators

operator + (Sink<A> lhs, Conduit<A, B> rhs) Source #

Combine two Sinkes into a single Source. The values are both merged into a new Sink.

Parameters

param lhs

Left hand side

param rhs

Right hand side

returns

Merged stream of values

operator + (Conduit<A, B> lhs, Source<B> rhs) Source #

Combine two Sourcees into a single Source. The value streams are both merged into a new stream. Values are yielded as they become available.

Parameters

param lhs

Left hand side

param rhs

Right hand side

returns

Merged stream of values

operator | (Conduit<A, B> lhs, Source<B> rhs) Source #

Choose a value from the first Source to successfully yield

Parameters

param lhs

Left hand side

param rhs

Right hand side

returns

Value from the lhs Source if there are any available, if not, from rhs. If rhs is also empty then Errors.SourceChannelClosed is raised

class Conduit Source #

Methods

method Conduit<A, A> spawn <A> (string label = "[unlabeled]") Source #

Create a new unbounded Conduit

Parameters

type A

Value type

param label

Label for debugging purposes

returns

Constructed Conduit with an Sink and an Source

method Conduit<A, A> spawn <A> (Buffer<A> buffer, string label = "[unlabeled]") Source #

Create a new Conduit with the buffer settings provided

Parameters

type A

Value type

param buffer

Buffer settings

param label

Label for debugging purposes

returns

Constructed Conduit with an Sink and an Source