LanguageExt.Core

LanguageExt.Core Traits Monads MonadIO

Contents

class MonadIOExtensions Source #

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

Parameters

type M

Self referring trait

Methods

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

where M : MonadIO<M>, Monad<M>

Convert an action in mato an action in IO.

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

where M : MonadIO<M>, Monad<M>

Convert an action in mato an action in IO.

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

where M : MonadIO<M>, Monad<M>

Map the underlying IO monad

class MonadIO Source #

Monad module

Methods

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

where M : Monad<M>

Embeds the IO monad into the M〈A〉 monad. NOTE: This will fail if the monad transformer stack doesn't have an IO monad as its innermost monad.

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

where M : Monad<M>

Embeds the IO monad into the M〈A〉 monad. NOTE: This will fail if the monad transformer stack doesn't have an IO monad as its innermost monad.

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

where M : Monad<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 : MonadIO<M>, Monad<M>

Map the underlying IO monad

interface MonadIO <M> Source #

where M : MonadIO<M>, Monad<M>

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

Parameters

type M

Self referring trait

Methods

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

Lifts the IO monad into a monad transformer stack.

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

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

Parameters

type A

Bound value type

param ma

IO computation to lift

returns

The outer monad with the IO monad lifted into it

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

Lifts the IO monad into a monad transformer stack.

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

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

Parameters

type A

Bound value type

param ma

IO computation to lift

returns

The outer monad with the IO monad lifted into it

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).

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, 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 a 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> Await <A> (K<M, ForkIO<A>> ma) Source #

Await a forked operation

method K<M, ForkIO<A>> ForkIO <A> (K<M, A> ma, Option<TimeSpan> timeout = default) 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> 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 has 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 #