LanguageExt.Core

LanguageExt.Core Traits Monads MonadUnliftIO

Contents

class MonadUnliftIOExtensions Source #

Methods

method K<M, A> LocalIO <M, A> (this K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Creates a local cancellation environment

A local cancellation environment stops other IO computations, that rely on the same environmental cancellation token, from being taken down by a regional cancellation.

If an IO.cancel is invoked locally, then it will still create an exception that propagates upwards and so catching cancellations is still important.

Parameters

type A

Bound value

param ma

Computation to run within the local context

returns

Result of the computation

method K<M, A> PostIO <M, A> (this K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Make this IO computation run on the SynchronizationContext that was captured at the start of the IO chain (i.e. the one embedded within the EnvIO environment that is passed through all IO computations)

method K<M, A> Await <M, A> (this K<M, ForkIO<A>> ma) Source #

where M : MonadUnliftIO<M>

Await a forked operation

method K<M, A> TimeoutIO <M, A> (this K<M, A> ma, TimeSpan timeout) Source #

where M : MonadUnliftIO<M>

Timeout operation if it takes too long

method K<M, A> BracketIO <M, A> (this K<M, A> ma) Source #

where M : MonadUnliftIO<M>

The IO monad tracks resources automatically, this creates a local resource environment to run this computation in. Once the computation has completed any resources acquired are automatically released. Imagine this as the ultimate using statement.

method K<M, C> BracketIO <M, A, B, C> ( this K<M, A> Acq, Func<A, IO<C>> Use, Func<A, IO<B>> Fin) Source #

where M : MonadUnliftIO<M>

When acquiring, using, and releasing various resources, it can be quite convenient to write a function to manage the acquisition and releasing, taking a function of the acquired value that specifies an action to be performed in between.

Parameters

param Acq

Resource acquisition

param Use

Function to use the acquired resource

param Fin

Function to invoke to release the resource

method K<M, C> BracketIO <M, A, B, C> ( this K<M, A> Acq, Func<A, IO<C>> Use, Func<Error, IO<C>> Catch, Func<A, IO<B>> Fin) Source #

where M : MonadUnliftIO<M>

When acquiring, using, and releasing various resources, it can be quite convenient to write a function to manage the acquisition and releasing, taking a function of the acquired value that specifies an action to be performed in between.

Parameters

param Acq

Resource acquisition

param Use

Function to use the acquired resource

param Catch

Function to run to handle any exceptions

param Fin

Function to invoke to release the resource

method K<M, A> RepeatIO <M, A> (this K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation forever, or until an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

returns

The result of the last invocation

method K<M, A> RepeatIO <M, A> ( this K<M, A> ma, Schedule schedule) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation, until the scheduler expires, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

returns

The result of the last invocation

method K<M, A> RepeatWhileIO <M, A> ( this K<M, A> ma, Func<A, bool> predicate) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation until the predicate returns false, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param predicate

Keep repeating while this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatWhileIO <M, A> ( this K<M, A> ma, Schedule schedule, Func<A, bool> predicate) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation, until the scheduler expires, or the predicate returns false, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

param predicate

Keep repeating while this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatUntilIO <M, A> ( this K<M, A> ma, Func<A, bool> predicate) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation until the predicate returns true, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param predicate

Keep repeating until this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatUntilIO <M, A> ( this K<M, A> ma, Schedule schedule, Func<A, bool> predicate) Source #

where M : MonadUnliftIO<M>

Keeps repeating the computation, until the scheduler expires, or the predicate returns true, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

param predicate

Keep repeating until this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RetryIO <M, A> (this K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will retry forever

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryIO <M, A> ( this K<M, A> ma, Schedule schedule) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will retry until the schedule expires

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryWhileIO <M, A> ( this K<M, A> ma, Func<Error, bool> predicate) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will keep retrying whilst the predicate returns true for the error generated at each iteration; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryWhileIO <M, A> ( this K<M, A> ma, Schedule schedule, Func<Error, bool> predicate) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will keep retrying whilst the predicate returns true for the error generated at each iteration; or, until the schedule expires; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryUntilIO <M, A> ( this K<M, A> ma, Func<Error, bool> predicate) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will keep retrying until the predicate returns true for the error generated at each iteration; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryUntilIO <M, A> ( this K<M, A> ma, Schedule schedule, Func<Error, bool> predicate) Source #

where M : MonadUnliftIO<M>

Retry if the IO computation fails

This variant will keep retrying until the predicate returns true for the error generated at each iteration; or, until the schedule expires; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, S> FoldIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldWhileIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

where M : MonadUnliftIO<M>

method K<M, S> FoldUntilIO <M, S, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

where M : MonadUnliftIO<M>

class MonadUnliftIO Source #

Monad module

Methods

method K<M, IO<A>> toIO <M, A> (K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Get the IO monad from within the M monad

This only works if the M trait implements MonadIO.ToIO.

method K<M, B> mapIO <M, A, B> (Func<IO<A>, IO<B>> f, K<M, A> ma) Source #

where M : MonadUnliftIO<M>

Map the underlying IO monad

interface MonadUnliftIO <M> Source #

where M : MonadUnliftIO<M>

Monad that is either the IO monad or a transformer with the IO monad in its stack.

'Unlifting' allows us to get at the nested IO monad and work on it, then to repackage it wherever it is in the transformer stack. This allows all IO functionality to work on any type that encapsulates the IO monad.

This opens up a ton of default functionality for monads that are able to support unlifting. It must be stated that not all monads are capable of supporting unlifting. It's usually the case that if they have a complex return type (like a union) then they can't support unlifting without compromising the integrity of the monad.

Parameters

type M

Self-referring trait

Methods

method K<M, IO<A>> ToIO <A> (K<M, A> ma) Source #

Extract the IO monad from within the M monad (usually as part of a monad-transformer stack).

IMPLEMENTATION REQUIRED: If this method isn't overloaded in this monad or any monad in the stack on the way to the inner-monad, then it will throw an exception.

This isn't ideal, it appears to be the only way to achieve this kind of functionality in C# without resorting to magic.

method K<M, B> MapIO <A, B> (K<M, A> ma, Func<IO<A>, IO<B>> f) Source #

Extract the IO monad from within the M monad (usually as part of a monad-transformer stack). Then perform a mapping operation on the IO action before lifting the IO back into the M monad.

method K<M, ForkIO<A>> ForkIO <A> (K<M, A> ma, Option<TimeSpan> timeout) Source #

Queue this IO operation to run on the thread-pool.

Parameters

param timeout

Maximum time that the forked IO operation can run for. None for no timeout.

returns

Returns a ForkIO data-structure that contains two IO effects that can be used to either cancel the forked IO operation or to await the result of it.

method K<M, A> Await <A> (K<M, ForkIO<A>> ma) Source #

Await a forked operation

method K<M, A> LocalIO <A> (K<M, A> ma) Source #

Creates a local cancellation environment

A local cancellation environment stops other IO computations, that rely on the same environmental cancellation token, from being taken down by a regional cancellation.

If an IO.cancel is invoked locally, then it will still create an exception that propagates upwards and so catching cancellations is still important.

Parameters

type A

Bound value

param ma

Computation to run within the local context

returns

Result of the computation

method K<M, A> PostIO <A> (K<M, A> ma) Source #

Make this IO computation run on the SynchronizationContext that was captured at the start of the IO chain (i.e. the one embedded within the EnvIO environment that is passed through all IO computations)

method K<M, A> TimeoutIO <A> (K<M, A> ma, TimeSpan timeout) Source #

Timeout operation if it takes too long

method K<M, A> BracketIO <A> (K<M, A> ma) Source #

The IO monad tracks resources automatically; this creates a local resource environment to run this computation in. Once the computation is completed, any resources acquired are automatically released. Imagine this as the ultimate using statement.

method K<M, C> BracketIO <A, B, C> ( K<M, A> Acq, Func<A, IO<C>> Use, Func<A, IO<B>> Fin) Source #

When acquiring, using, and releasing various resources, it can be quite convenient to write a function to manage the acquisition and releasing, taking a function of the acquired value that specifies an action to be performed in between.

Parameters

param Acq

Resource acquisition

param Use

Function to use the acquired resource

param Fin

Function to invoke to release the resource

method K<M, C> BracketIO <A, B, C> ( K<M, A> Acq, Func<A, IO<C>> Use, Func<Error, IO<C>> Catch, Func<A, IO<B>> Fin) Source #

When acquiring, using, and releasing various resources, it can be quite convenient to write a function to manage the acquisition and releasing, taking a function of the acquired value that specifies an action to be performed in between.

Parameters

param Acq

Resource acquisition

param Use

Function to use the acquired resource

param Catch

Function to run to handle any exceptions

param Fin

Function to invoke to release the resource

method K<M, A> RepeatIO <A> (K<M, A> ma) Source #

Keeps repeating the computation forever, or until an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

returns

The result of the last invocation

method K<M, A> RepeatIO <A> ( K<M, A> ma, Schedule schedule) Source #

Keeps repeating the computation until the scheduler expires, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

returns

The result of the last invocation

method K<M, A> RepeatWhileIO <A> ( K<M, A> ma, Func<A, bool> predicate) Source #

Keeps repeating the computation until the predicate returns false, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param predicate

Keep repeating while this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatWhileIO <A> ( K<M, A> ma, Schedule schedule, Func<A, bool> predicate) Source #

Keeps repeating the computation until the scheduler expires, or the predicate returns false, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

param predicate

Keep repeating while this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatUntilIO <A> ( K<M, A> ma, Func<A, bool> predicate) Source #

Keeps repeating the computation until the predicate returns true, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param predicate

Keep repeating until this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RepeatUntilIO <A> ( K<M, A> ma, Schedule schedule, Func<A, bool> predicate) Source #

Keeps repeating the computation until the scheduler expires, or the predicate returns true, or an error occurs

Any resources acquired within a repeated IO computation will automatically be released. This also means you can't acquire resources and return them from within a repeated computation.

Parameters

param schedule

Scheduler strategy for repeating

param predicate

Keep repeating until this predicate returns true for each computed value

returns

The result of the last invocation

method K<M, A> RetryIO <A> (K<M, A> ma) Source #

Retry if the IO computation fails

This variant will retry forever

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryIO <A> ( K<M, A> ma, Schedule schedule) Source #

Retry if the IO computation fails

This variant will retry until the schedule expires

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryWhileIO <A> ( K<M, A> ma, Func<Error, bool> predicate) Source #

Retry if the IO computation fails

This variant will keep retrying whilst the predicate returns true for the error generated at each iteration; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryWhileIO <A> ( K<M, A> ma, Schedule schedule, Func<Error, bool> predicate) Source #

Retry if the IO computation fails

This variant will keep retrying whilst the predicate returns true for the error generated at each iteration; or, until the schedule expires; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryUntilIO <A> ( K<M, A> ma, Func<Error, bool> predicate) Source #

Retry if the IO computation fails

This variant will keep retrying until the predicate returns true for the error generated at each iteration; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, A> RetryUntilIO <A> ( K<M, A> ma, Schedule schedule, Func<Error, bool> predicate) Source #

Retry if the IO computation fails

This variant will keep retrying until the predicate returns true for the error generated at each iteration; or, until the schedule expires; at which point the last raised error will be thrown.

Any resources acquired within a retrying IO computation will automatically be released if the operation fails. So, successive retries will not grow the acquired resources on each retry iteration. Any successful operation that acquires resources will have them tracked in the usual way.

method K<M, S> FoldIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder) Source #

method K<M, S> FoldIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method K<M, S> FoldWhileIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method K<M, S> FoldUntilIO <S, A> ( K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #