LanguageExt.Pipes

LanguageExt.Pipes Concurrent Mailbox

Contents

record Mailbox <A, B> (Inbox<A> Inbox, Outbox<B> Outbox) Source #

Represents a channel. A channel has:

  • An Inbox: a queue of values that are its input.
  • An Outbox: a stream of values that are its output.

Both sides of the mailbox can be manipulated:

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

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

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

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

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

Parameters

type A

Input value type

type B

Output value type

param Inbox

Inbox

param Outbox

Outbox

Methods

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

Post a value to the inbox

Raises Errors.NoSpaceInInbox if the inbox 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 outbox

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

Parameters

returns

First available value from the channel

method IO<Unit> Complete () Source #

Complete and close the inbox

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

Complete and close the inbox with an Error

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

Functor map

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

Monad bind

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

Applicative apply

method Mailbox<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 Inbox 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 Inbox to a Consumer pipe component

Parameters

returns

Consumer

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

where M : Monad<M>

Convert Outbox 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 Outbox to a Producer pipe component

Parameters

returns

Producer

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

Combine two Inboxes: lhs and rhs into a single inbox that takes incoming values and then posts the to the lhs and rhs inboxes.

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

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

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

Combine two outboxes into a single outbox. 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 Mailbox<A, B> Choose (Outbox<B> rhs) Source #

Choose a value from the first Outbox to successfully yield

Parameters

param rhs
returns

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

Operators

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

Combine two inboxes into a single outbox. The values are both merged into a new inbox.

Parameters

param lhs

Left hand side

param rhs

Right hand side

returns

Merged stream of values

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

Combine two outboxes into a single outbox. 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 | (Mailbox<A, B> lhs, Outbox<B> rhs) Source #

Choose a value from the first Outbox to successfully yield

Parameters

param lhs

Left hand side

param rhs

Right hand side

returns

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

class Mailbox Source #

Methods

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

Create a new unbounded mailbox

Parameters

type A

Value type

param label

Label for debugging purposes

returns

Constructed mailbox with an Inbox and an Outbox

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

Create a new mailbox with the buffer settings provided

Parameters

type A

Value type

param buffer

Buffer settings

param label

Label for debugging purposes

returns

Constructed mailbox with an Inbox and an Outbox