LanguageExt.Core

LanguageExt.Core Effects IO

Contents

Sub modules

Async
Fail
Pure
Sync

class EnvIO Source #

Environment for the IO monad

Fields

field Resources Resources Source #

field CancellationToken Token Source #

field CancellationTokenSource Source Source #

field SynchronizationContext? SyncContext Source #

Properties

property EnvIO Local Source #

property EnvIO LocalResources Source #

property EnvIO LocalCancel Source #

property EnvIO LocalSyncContext Source #

Methods

method EnvIO New ( Resources? resources = null, CancellationToken token = default, CancellationTokenSource? source = null, SynchronizationContext? syncContext = null) Source #

method void Dispose () Source #

method string ToString () Source #

record ForkIO <A> ( IO<Unit> Cancel, IO<A> Await) Source #

Result of forking an IO monad

Parameters

type A

Bound value type

param Cancel

An IO monad, which, if invoked, would cancel the forked IO operation

param Await

An IO monad, which, if invoked, would await the result of the forked IO operation. Obviously, this mitigates the reasons for forking somewhat, but this struct could be passed to another process that does the awaiting - and so still has some value.

record IO <A> Source #

A value of type IO is a computation which, when performed, does some I/O before returning a value of type A.

There is really only one way you should "perform" an I/O action: bind it to Main in your program: When your program is run, the I/O will be performed. It shouldn't be possible to perform I/O from an arbitrary function, unless that function is itself in the IO monad and called at some point, directly or indirectly, from Main.

Obviously, as this is C#, the above restrictions are for you to enforce. It would be reasonable to relax that approach and have I/O invoked from, say, web-request handlers - or any other 'edges' of your application.

IO is a monad, so IO actions can be combined using either the LINQ-notation or the bind operations from the Monad class.

Parameters

type A

Bound value

param runIO

The lifted thunk that is the IO operation

Properties

property IO<A> Empty Source #

Methods

method IO<A> Pure (A value) Source #

method IO<A> Fail (Error value) Source #

method IO<A> Lift (Func<A> f) Source #

method IO<A> Lift (Func<IOResponse<A>> f) Source #

method IO<A> Lift (Func<EnvIO, A> f) Source #

method IO<A> Lift (Func<EnvIO, IOResponse<A>> f) Source #

method IO<A> LiftAsync (Func<Task<IOResponse<A>>> f) Source #

method IO<A> LiftAsync (Func<EnvIO, Task<IOResponse<A>>> f) Source #

method IO<A> LiftAsync (Func<Task<A>> f) Source #

method IO<A> LiftAsync (Func<EnvIO, Task<A>> f) Source #

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

method IO<B> Map <B> (B value) Source #

method IO<A> MapFail (Func<Error, Error> f) Source #

method IO<B> BiMap <B> (Func<A, B> Succ, Func<Error, Error> Fail) Source #

method IO<B> Match <B> (Func<A, B> Succ, Func<Error, B> Fail) Source #

method IO<A> IfFail (Func<Error, A> Fail) Source #

method IO<A> IfFail (A Fail) Source #

method IO<A> IfFail (Func<Error, IO<A>> Fail) Source #

method IO<A> IfFail (IO<A> Fail) Source #

method IO<S> Fold <S> ( Schedule schedule, S initialState, Func<S, A, S> folder) Source #

method IO<S> Fold <S> ( S initialState, Func<S, A, S> folder) Source #

method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method IO<S> FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method IO<S> FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method IO<S> FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method IO<S> FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #

method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method IO<S> FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #

method IO<S> FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #

method IO<A> Post () 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 IO<B> Bind <B> (Func<A, IO<B>> f) Source #

method IO<B> Bind <B> (Func<A, K<IO, B>> f) Source #

method IO<B> Bind <B> (Func<A, Pure<B>> f) Source #

method IO<B> Select <B> (Func<A, B> f) Source #

method IO<C> SelectMany <B, C> (Func<A, IO<B>> bind, Func<A, B, C> project) Source #

method IO<C> SelectMany <B, C> (Func<A, K<IO, B>> bind, Func<A, B, C> project) Source #

method IO<C> SelectMany <B, C> (Func<A, Pure<B>> bind, Func<A, B, C> project) Source #

method OptionT<M, C> SelectMany <M, B, C> (Func<A, OptionT<M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method TryT<M, C> SelectMany <M, B, C> (Func<A, TryT<M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method EitherT<L, M, C> SelectMany <L, M, B, C> (Func<A, EitherT<L, M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method FinT<M, C> SelectMany <M, B, C> (Func<A, FinT<M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method ValidationT<F, M, C> SelectMany <F, M, B, C> (Func<A, ValidationT<F, M, B>> bind, Func<A, B, C> project) Source #

where F : Monoid<F>
where M : Monad<M>, Alternative<M>

method ReaderT<Env, M, C> SelectMany <Env, M, B, C> (Func<A, ReaderT<Env, M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method StateT<S, M, C> SelectMany <S, M, B, C> (Func<A, StateT<S, M, B>> bind, Func<A, B, C> project) Source #

where M : Monad<M>, Alternative<M>

method Eff<C> SelectMany <B, C> (Func<A, Eff<B>> bind, Func<A, B, C> project) Source #

method Eff<RT, C> SelectMany <RT, B, C> (Func<A, Eff<RT, B>> bind, Func<A, B, C> project) Source #

method IO<C> SelectMany <C> (Func<A, Guard<Error, Unit>> bind, Func<A, Unit, C> project) Source #

method IO<A> Bracket () 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 IO<C> Bracket <B, C> (Func<A, IO<C>> Use, Func<A, IO<B>> Finally) 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 Use

Function to use the acquired resource

param Finally

Function to invoke to release the resource

method IO<C> Bracket <B, C> (Func<A, IO<C>> Use, Func<Error, IO<C>> Catch, Func<A, IO<B>> Finally) 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 Use

Function to use the acquired resource

param Catch

Function to run to handle any exceptions

param Finally

Function to invoke to release the resource

method IO<A> Timeout (TimeSpan timeout) Source #

Applies a time limit to the IO computation. If exceeded an exception is thrown.

Parameters

param timeout

Timeout

returns

Result of the operation or throws if the time limit exceeded.

method IO<A> Local () Source #

Create a local cancellation environment

method IO<ForkIO<A>> Fork (Option<TimeSpan> timeout = default) Source #

Queues the specified work to run on the thread pool

Any resources acquired within a forked IO computation will automatically be released upon the forked computation's completion (successful or otherwise). Resources acquired in the parent thread will be available to the forked thread, and can be released from there, but they are shared resources at that point and should be treated with care.

Parameters

param timeout

Optional timeout

returns

Fork record that contains members for cancellation and optional awaiting

method ValueTask<A> RunAsync (EnvIO? envIO = null) Source #

Run the IO monad to get its result

This forks the operation to run on a new task that is then awaited.

Any lifted asynchronous operations will yield to the thread-scheduler, allowing other queued operations to run concurrently. So, even though this call isn't awaitable it still plays nicely and doesn't block the thread.

NOTE: An exception will always be thrown if the IO operation fails. Lift this monad into other error handling monads to leverage more declarative error handling.

Parameters

returns

Result of the IO operation

method A Run (EnvIO? envIO = null) Source #

Run the IO monad to get its result

Any lifted asynchronous operations will yield to the thread-scheduler, allowing other queued operations to run concurrently. So, even though this call isn't awaitable it still plays nicely and doesn't block the thread.

NOTE: An exception will always be thrown if the IO operation fails. Lift this monad into other error handling monads to leverage more declarative error handling.

Parameters

param env

IO environment

returns

Result of the IO operation

method FinT<IO, A> Try () Source #

Run the IO monad to get its result. Differs from Run in that it catches any exceptions and turns them into a Fin<A> result.

method IO<A> Repeat () 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 IO<A> Repeat (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 IO<A> RepeatWhile (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 IO<A> RepeatWhile ( 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 IO<A> RepeatUntil ( 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 IO<A> RepeatUntil ( 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 IO<A> Retry () 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 IO<A> Retry (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 IO<A> RetryWhile (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 IO<A> RetryWhile ( 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 IO<A> RetryUntil ( 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 IO<A> RetryUntil ( 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 IO<A> Catch (Func<Error, bool> Predicate, Func<Error, K<IO, A>> Fail) Source #

Catches any error thrown by invoking this IO computation, passes it through a predicate, and if that returns true, returns the result of invoking the Fail function, otherwise this is returned.

Parameters

param Predicate

Predicate

param Fail

Fail functions

method IO<A> Combine (IO<A> rhs) Source #

Monoid combine

Parameters

param rhs

Alternative

returns

This if computation runs without error. rhs otherwise

method string ToString () Source #

Operators

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

operator | (IO<A> lhs, K<IO, A> rhs) Source #

operator | (K<IO, A> lhs, IO<A> rhs) Source #

operator | (IO<A> lhs, Pure<A> rhs) Source #

operator | (IO<A> lhs, Fail<Error> rhs) Source #

operator | (IO<A> lhs, CatchM<Error, IO, A> rhs) Source #

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

operator >> (IO<A> lhs, IO<A> rhs) Source #

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in C#.

Parameters

param lhs

First action to run

param rhs

Second action to run

returns

Result of the second action

operator >> (IO<A> lhs, K<IO, A> rhs) Source #

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in C#.

Parameters

param lhs

First action to run

param rhs

Second action to run

returns

Result of the second action

operator >> (IO<A> lhs, IO<Unit> rhs) Source #

Sequentially compose two actions. The second action is a unit returning action, so the result of the first action is propagated.

Parameters

param lhs

First action to run

param rhs

Second action to run

returns

Result of the first action

operator >> (IO<A> lhs, K<IO, Unit> rhs) Source #

Sequentially compose two actions. The second action is a unit returning action, so the result of the first action is propagated.

Parameters

param lhs

First action to run

param rhs

Second action to run

returns

Result of the first action

record IOResponse <A> Source #

record CompleteIO <A> (A Value) Source #

record RecurseIO <A> (IO<A> Computation) Source #

record BindIO <A> Source #

Methods

method IO<A> Run () Source #

record BindIO <X, A> (X Value, Func<X, IO<A>> Computation) Source #

Methods

method IO<A> Run () Source #

class IOResponse Source #

Methods

method IOResponse<A> Complete <A> (A value) Source #

method IOResponse<A> Recurse <A> (IO<A> computation) Source #

method IOResponse<A> Bind <X, A> (X value, Func<X, IO<A>> computation) Source #

class IOExtensions Source #

Methods

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

Convert the kind version of the IO monad to an IO monad.

This is a simple cast operation which is just a bit more elegant than manually casting.

Parameters

type A
param ma
returns

method A Run <A> (this K<IO, A> ma, EnvIO? envIO = null) Source #

method Fin<A> RunSafe <A> (this K<IO, A> ma, EnvIO? envIO = null) Source #

method ValueTask<A> RunAsync <A> (this K<IO, A> ma, EnvIO? envIO = null) Source #

method ValueTask<Fin<A>> RunSafeAsync <A> (this K<IO, A> ma, EnvIO? envIO = null) Source #

method IO<A> Flatten <A> (this Task<IO<A>> tma) Source #

Get the outer task and wrap it up in a new IO within the IO

method IO<A> Flatten <A> (this IO<IO<A>> mma) Source #

Unwrap the inner IO to flatten the structure

method IO<C> SelectMany <A, B, C> (this K<IO, A> ma, Func<A, K<IO, B>> bind, Func<A, B, C> project) Source #

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

where M : Monad<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 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 <M, A> (this K<M, A> ma) Source #

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

Await a forked operation

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

where M : Monad<M>

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, ForkIO<Option<A>>> ForkIO <M, A> (this StreamT<M, A> ma, Option<TimeSpan> timeout = default) Source #

where M : Monad<M>

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 <M, A> (this K<M, A> ma, TimeSpan timeout) Source #

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

Timeout operation if it takes too long

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

where M : Monad<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>> Finally) Source #

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

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>> Finally) Source #

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

Function to invoke to release the resource

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

where M : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 : Monad<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 <S, M, A> ( this K<M, A> ma, Schedule schedule, S initialState, Func<S, A, S> folder) Source #

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

method K<M, S> FoldWhileIO <S, M, 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 : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

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

where M : Monad<M>

method K<M, S> FoldUntilIO <S, M, 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 : Monad<M>

method K<M, (A First, B Second)> ZipIO <M, A, B> ( this (K<M, A> First, K<M, B> Second) tuple) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

param tuple

Tuple of IO monads to run

returns

IO monad

method K<M, (A First, B Second, C Third)> ZipIO <M, A, B, C> ( this (K<M, A> First, K<M, B> Second, K<M, C> Third) tuple) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

type C

Third IO monad bound value type

param tuple

Tuple of IO monads to run

returns

IO monad

method K<M, (A First, B Second, C Third, D Fourth)> ZipIO <M, A, B, C, D> ( this (K<M, A> First, K<M, B> Second, K<M, C> Third, K<M, D> Fourth) tuple) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

type C

Third IO monad bound value type

type D

Fourth IO monad bound value type

param tuple

Tuple of IO monads to run

returns

IO monad

method K<M, (A First, B Second)> ZipIO <M, A, B> ( this K<M, A> First, K<M, B> Second) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

returns

IO monad

method K<M, (A First, B Second, C Third)> ZipIO <M, A, B, C> ( this K<M, A> First, K<M, B> Second, K<M, C> Third) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

type C

Third IO monad bound value type

returns

IO monad

method K<M, (A First, B Second, C Third, D Fourth)> ZipIO <M, A, B, C, D> ( this K<M, A> First, K<M, B> Second, K<M, C> Third, K<M, D> Fourth) Source #

where M : Monad<M>

Takes two IO monads and zips their result

Asynchronous operations will run concurrently

Parameters

type M

Monad trait type

type A

First IO monad bound value type

type B

Second IO monad bound value type

type C

Third IO monad bound value type

type D

Fourth IO monad bound value type

returns

IO monad

class IOExtensions Source #

Methods

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

Functor map operation

Unwraps the value within the functor, passes it to the map function f provided, and then takes the mapped value and wraps it back up into a new functor.

Parameters

param ma

Functor to map

param f

Mapping function

returns

Mapped functor

method IO<B> Map <A, B> (this Func<A, B> f, IO<A> ma) Source #

Functor map operation

Unwraps the value within the functor, passes it to the map function f provided, and then takes the mapped value and wraps it back up into a new functor.

Parameters

param ma

Functor to map

param f

Mapping function

returns

Mapped functor

method IO<B> Action <A, B> (this IO<A> ma, IO<B> mb) Source #

Applicative action: runs the first applicative, ignores the result, and returns the second applicative

method IO<B> Apply <A, B> (this IO<Func<A, B>> mf, K<IO, A> ma) Source #

Applicative functor apply operation

Unwraps the value within the ma applicative-functor, passes it to the unwrapped function(s) within mf, and then takes the resulting value and wraps it back up into a new applicative-functor.

Parameters

param ma

Value(s) applicative functor

param mf

Mapping function(s)

returns

Mapped applicative functor

method IO<B> Apply <A, B> (this K<IO, Func<A, B>> mf, K<IO, A> ma) Source #

Applicative functor apply operation

Unwraps the value within the ma applicative-functor, passes it to the unwrapped function(s) within mf, and then takes the resulting value and wraps it back up into a new applicative-functor.

Parameters

param ma

Value(s) applicative functor

param mf

Mapping function(s)

returns

Mapped applicative functor

class IO Source #

Fields

field IO<EnvIO> env = lift(e => e) Source #

field IO<CancellationToken> token = lift(e => e.Token) Source #

field IO<CancellationTokenSource> source = lift(e => e.Source) Source #

field IO<Option<SynchronizationContext>> syncContext = lift(e => Optional(e.SyncContext)) Source #

Methods

method IO<A> fail <A> (Error value) Source #

Put the IO into a failure state

Parameters

type A

Bound value type

param value

Error value

returns

IO in a failed state. Always yields an error.

method IO<A> fail <A> (string value) Source #

Put the IO into a failure state

Parameters

type A

Bound value type

param value

Error value

returns

IO in a failed state. Always yields an error.

method IO<Unit> lift (Action f) Source #

Lift an action into the IO monad

Parameters

param f

Action to lift

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

where M : Monad<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 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 IO<A> local <A> (K<IO, 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 IO<A> lift <A> (Either<Error, A> ma) Source #

method IO<A> lift <A> (Fin<A> ma) Source #

method IO<A> lift <A> (Func<A> f) Source #

method IO<A> lift <A> (Func<EnvIO, A> f) Source #

method IO<A> lift <A> (Func<Fin<A>> f) Source #

method IO<A> lift <A> (Func<EnvIO, Fin<A>> f) Source #

method IO<A> lift <A> (Func<Either<Error, A>> f) Source #

method IO<A> lift <A> (Func<EnvIO, Either<Error, A>> f) Source #

method IO<A> liftAsync <A> (Func<Task<A>> f) Source #

method IO<A> liftAsync <A> (Func<EnvIO, Task<A>> f) Source #

method IO<A> empty <A> () Source #

method IO<A> combine <A> (K<IO, A> ma, K<IO, A> mb) Source #

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

where M : Monad<M>

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

where M : Monad<M>

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 IO<Unit> yieldFor (Duration duration) Source #

Yield the thread for the specified duration or until cancelled.

Parameters

param duration

Amount of time to yield for

returns

Unit

method IO<Unit> yieldFor (TimeSpan timeSpan) Source #

Yield the thread for the specified duration or until cancelled.

Parameters

param timeSpan

Amount of time to yield for

returns

Unit

class IO Source #

Methods

method IO<A> pure <A> (A value) Source #

class Prelude Source #

Methods

method IO<Ref<A>> refIO <A> (A value, Func<A, bool>? validator = null) Source #

Generates a new reference that can be used within a sync transaction

Refs ensure safe shared use of mutable storage locations via a software transactional memory (STM) system. Refs are bound to a single storage location for their lifetime, and only allow mutation of that location to occur within a transaction.

Transactions (within a sync(() => ...)) should be easy to understand if you’ve ever used database transactions - they ensure that all actions on Refs are atomic, consistent, and isolated.

  • Atomic - means that every change to Refs made within a transaction occurs or none do.
  • Consistent - means that each new value can be checked with a validator function before allowing the transaction to commit.
  • Isolated - means that no transaction sees the effects of any other transaction while it is running.

Another feature common to STMs is that, should a transaction have a conflict while running, it is automatically retried. The language-ext STM uses multi-version concurrency control for snapshot and serialisable isolation.

In practice, this means:

All reads of Refs will see a consistent snapshot of the Ref world as of the starting point of the transaction (its 'read point'). The transaction will see any changes it has made. This is called the in-transaction-value.

All changes made to Refs during a transaction will appear to occur at a single point in the Ref world timeline (its 'write point').

No changes will have been made by any other transactions to any Refs that have been modified by this transaction.

  • Readers will never block writers, or other readers.

  • Writers will never block readers.

I/O and other activities with side effects should be avoided in transactions, since transactions will be retried.

If a constraint on the validity of a value of a Ref that is being changed depends upon the simultaneous value of a Ref that is not being changed, that second Ref can be protected from modification by running the sync transaction with Isolation.Serialisable.

The language-ext STM is designed to work with the persistent collections (Map, HashMap, Seq, Lst, Set, HashSet` etc.), and it is strongly recommended that you use the language-ext collections as the values of your Refs. Since all work done in an STM transaction is speculative, it is imperative that there be a low cost to making copies and modifications. Persistent collections have free copies (just use the original, it can’t be changed), and 'modifications' share structure efficiently. In any case:

The values placed in Refs must be, or be considered, immutable. Otherwise, this library can’t help you.

See the concurrency section of the wiki for more info.

Parameters

param value

Initial value of the ref

param validator

Validator that is called on the ref value just before any transaction is committed (within a sync)

method IO<R> atomicIO <R> (Func<R> op, Isolation isolation = Isolation.Snapshot) Source #

Snapshot isolation requires that nothing outside the transaction has written to any of the values that are written-to within the transaction. If anything does write to the values used within the transaction, then the transaction is rolled back and retried (using the latest 'world' state).

Serialisable isolation requires that nothing outside the transaction has written to any of the values that are read-from or written-to within the transaction. If anything does read from or written to the values used within the transaction, then it is rolled back and retried (using the latest 'world' state).

It is the strictest form of isolation, and the most likely to conflict; but protects against cross read/write inconsistencies. For example, if you have:

var x = Ref(1);
var y = Ref(2);

snapshot(() => x.Value = y.Value + 1);

Then something writing to y mid-way through the transaction would not cause the transaction to fail. Because y was only read-from, not written to. However, this:

var x = Ref(1);
var y = Ref(2);

serial(() => x.Value = y.Value + 1);

... would fail if something wrote to y.

method IO<Unit> atomicIO (Action op, Isolation isolation = Isolation.Snapshot) Source #

Run the op within a new transaction If a transaction is already running, then this becomes part of the parent transaction

Snapshot isolation requires that nothing outside the transaction has written to any of the values that are written-to within the transaction. If anything does write to the values used within the transaction, then the transaction is rolled back and retried (using the latest 'world' state).

Serialisable isolation requires that nothing outside the transaction has written to any of the values that are read-from or written-to within the transaction. If anything does read from or written to the values used within the transaction, then it is rolled back and retried (using the latest 'world' state).

It is the strictest form of isolation, and the most likely to conflict; but protects against cross read/write inconsistencies. For example, if you have:

var x = Ref(1);
var y = Ref(2);

snapshot(() => x.Value = y.Value + 1);

Then something writing to y mid-way through the transaction would not cause the transaction to fail. Because y was only read-from, not written to. However, this:

var x = Ref(1);
var y = Ref(2);

serial(() => x.Value = y.Value + 1);

... would fail if something wrote to y.

method IO<R> snapshotIO <R> (Func<R> op) Source #

Run the op within a new transaction If a transaction is already running, then this becomes part of the parent transaction

Snapshot isolation requires that nothing outside the transaction has written to any of the values that are written-to within the transaction. If anything does write to the values used within the transaction, then the transaction is rolled back and retried (using the latest 'world' state).

method IO<Unit> snapshotIO (Action op) Source #

Run the op within a new transaction If a transaction is already running, then this becomes part of the parent transaction

Snapshot isolation requires that nothing outside the transaction has written to any of the values that are written-to within the transaction. If anything does write to the values used within the transaction, then the transaction is rolled back and retried (using the latest 'world' state).

method IO<R> serialIO <R> (Func<R> op) Source #

Run the op within a new transaction If a transaction is already running, then this becomes part of the parent transaction

Serialisable isolation requires that nothing outside the transaction has written to any of the values that are read-from or written-to within the transaction. If anything does read from or written to the values used within the transaction, then it is rolled back and retried (using the latest 'world' state).

It is the strictest form of isolation, and the most likely to conflict; but protects against cross read/write inconsistencies. For example, if you have:

var x = Ref(1);
var y = Ref(2);

snapshot(() => x.Value = y.Value + 1);

Then something writing to y mid-way through the transaction would not cause the transaction to fail. Because y was only read-from, not written to. However, this:

var x = Ref(1);
var y = Ref(2);

serial(() => x.Value = y.Value + 1);

... would fail if something wrote to y.

method IO<Unit> serialIO (Action op) Source #

Run the op within a new transaction If a transaction is already running, then this becomes part of the parent transaction

Serialisable isolation requires that nothing outside the transaction has written to any of the values that are read-from or written-to within the transaction. If anything does read from or written to the values used within the transaction, then it is rolled back and retried (using the latest 'world' state).

It is the strictest form of isolation, and the most likely to conflict; but protects against cross read/write inconsistencies. For example, if you have:

var x = Ref(1);
var y = Ref(2);

snapshot(() => x.Value = y.Value + 1);

Then something writing to y mid-way through the transaction would not cause the transaction to fail. Because y was only read-from, not written to. However, this:

var x = Ref(1);
var y = Ref(2);

serial(() => x.Value = y.Value + 1);

... would fail if something wrote to y.

method IO<A> swapIO <A> (Ref<A> r, Func<A, A> f) Source #

method IO<A> commuteIO <A> (Ref<A> r, Func<A, A> f) Source #

Must be called in a transaction. Sets the in-transaction-value of ref to:

`f(in-transaction-value-of-ref)`

and returns the in-transaction-value when complete.

At the commit point of the transaction, f is run AGAIN with the most recently committed value:

`f(most-recently-committed-value-of-ref)`

Thus f should be commutative, or, failing that, you must accept last-one-in-wins behavior.

Commute allows for more concurrency than just setting the Ref's value

method IO<Atom<A>> atomIO <A> (A value) Source #

Atoms provide a way to manage shared, synchronous, independent state without locks.

The intended use of atom is to hold one an immutable data structure. You change the value by applying a function to the old value. This is done in an atomic manner by Swap.

Internally, Swap reads the current value, applies the function to it, and attempts to CompareExchange it in. Since another thread may have changed the value in the intervening time, it may have to retry, and does so in a spin loop.

The net effect is that the value will always be the result of the application of the supplied function to a current value, atomically. However, because the function might be called multiple times, it must be free of side effects.

Atoms are an efficient way to represent some state that will never need to be coordinated with any other, and for which you wish to make synchronous changes.

Parameters

param value

Initial value of the atom

returns

The constructed Atom

method IO<Atom<A>> atomIO <A> (A value, Func<A, bool> validator) Source #

Atoms provide a way to manage shared, synchronous, independent state without locks.

The intended use of atom is to hold one an immutable data structure. You change the value by applying a function to the old value. This is done in an atomic manner by Swap.

Internally, Swap reads the current value, applies the function to it, and attempts to CompareExchange it in. Since another thread may have changed the value in the intervening time, it may have to retry, and does so in a spin loop.

The net effect is that the value will always be the result of the application of the supplied function to a current value, atomically. However, because the function might be called multiple times, it must be free of side effects.

Atoms are an efficient way to represent some state that will never need to be coordinated with any other, and for which you wish to make synchronous changes.

Parameters

param value

Initial value of the atom

param validator

Function to run on the value after each state change.

If the function returns false for any proposed new state, then the swap function will return false, else it will return true on successful setting of the atom's state

returns

The constructed Atom or None if the validation faled for the initial value

method IO<Atom<M, A>> atomIO <M, A> (M metadata, A value) Source #

Atoms provide a way to manage shared, synchronous, independent state without locks.

The intended use of atom is to hold one an immutable data structure. You change the value by applying a function to the old value. This is done in an atomic manner by Swap.

Internally, Swap reads the current value, applies the function to it, and attempts to CompareExchange it in. Since another thread may have changed the value in the intervening time, it may have to retry, and does so in a spin loop.

The net effect is that the value will always be the result of the application of the supplied function to a current value, atomically. However, because the function might be called multiple times, it must be free of side effects.

Atoms are an efficient way to represent some state that will never need to be coordinated with any other, and for which you wish to make synchronous changes.

Parameters

param metadata

Metadata to be passed to the validation function

param value

Initial value of the atom

returns

The constructed Atom

method IO<Atom<M, A>> atomIO <M, A> (M metadata, A value, Func<A, bool> validator) Source #

Atoms provide a way to manage shared, synchronous, independent state without locks.

The intended use of atom is to hold one an immutable data structure. You change the value by applying a function to the old value. This is done in an atomic manner by Swap.

Internally, Swap reads the current value, applies the function to it, and attempts to CompareExchange it in. Since another thread may have changed the value in the intervening time, it may have to retry, and does so in a spin loop.

The net effect is that the value will always be the result of the application of the supplied function to a current value, atomically. However, because the function might be called multiple times, it must be free of side effects.

Atoms are an efficient way to represent some state that will never need to be coordinated with any other, and for which you wish to make synchronous changes.

Parameters

param metadata

Metadata to be passed to the validation function

param value

Initial value of the atom

param validator

Function to run on the value after each state change.

If the function returns false for any proposed new state, then the swap function will return false, else it will return true on successful setting of the atom's state

returns

The constructed Atom or None if the validation faled for the initial value

method IO<A> swapIO <A> (Atom<A> ma, Func<A, A> f) Source #

Atomically updates the value by passing the old value to f and updating the atom with the result. Note: f may be called multiple times, so it should be free of side effects.

Parameters

param f

Function to update the atom

returns

If the swap operation succeeded then a snapshot of the value that was set is returned. If the swap operation fails (which can only happen due to its validator returning false), then a snapshot of the current value within the Atom is returned. If there is no validator for the Atom then the return value is always the snapshot of the successful f function.

method IO<A> swapIO <M, A> (Atom<M, A> ma, Func<M, A, A> f) Source #

Atomically updates the value by passing the old value to f and updating the atom with the result. Note: f may be called multiple times, so it should be free of side effects.

Parameters

param f

Function to update the atom

returns

If the swap operation succeeded then a snapshot of the value that was set is returned. If the swap operation fails (which can only happen due to its validator returning false), then a snapshot of the current value within the Atom is returned. If there is no validator for the Atom then the return value is always the snapshot of the successful f function.

method IO<A> swapIO <A> (Atom<A> ma, Func<A, Option<A>> f) Source #

Atomically updates the value by passing the old value to f and updating the atom with the result. Note: f may be called multiple times, so it should be free of side effects.

Parameters

param f

Function to update the atom

returns
  • If f returns None then no update occurs and the result of the call to Swap will be the latest (unchanged) value of A.
  • If the swap operation fails, due to its validator returning false, then a snapshot of the current value within the Atom is returned.
  • If the swap operation succeeded then a snapshot of the value that was set is returned.
  • If there is no validator for the Atom then the return value is always the snapshot of the successful f function.

method IO<A> swapIO <M, A> (Atom<M, A> ma, Func<M, A, Option<A>> f) Source #

Atomically updates the value by passing the old value to f and updating the atom with the result. Note: f may be called multiple times, so it should be free of side effects.

Parameters

param f

Function to update the atom

returns
  • If f returns None then no update occurs and the result of the call to Swap will be the latest (unchanged) value of A.
  • If the swap operation fails, due to its validator returning false, then a snapshot of the current value within the Atom is returned.
  • If the swap operation succeeded then a snapshot of the value that was set is returned.
  • If there is no validator for the Atom then the return value is always the snapshot of the successful f function.

method IO<A> valueIO <A> (Atom<A> ma) Source #

Retrieve an IO computation that on each invocation will snapshot of the value in an atom

Parameters

type A

Value type

param ma

Atom to snapshot

returns

IO representation of the snapshot

method IO<A> valueIO <M, A> (Atom<M, A> ma) Source #

Retrieve an IO computation that on each invocation will snapshot of the value in an atom

Parameters

type A

Value type

param ma

Atom to snapshot

returns

IO representation of the snapshot

method IO<A> writeIO <A> (Atom<A> ma, A value) Source #

Write a value to an atom.

Note, this can be dangerous and is usually better to use swapIO if the value is derived from a snapshot of the atom's value (via valueIO).

The computation is better run inside the swap operation for atomic consistency.

However, using writeIO is reasonable if this is simply a forceful overwrite of the atomic value without any dependency on the previous state.

Parameters

type A

Value type

param ma

Atom to write

returns

IO representation of the write operation

method IO<A> writeIO <M, A> (Atom<M, A> ma, A value) Source #

Write a value to an atom.

Note, this can be dangerous and is usually better to use swapIO if the value is derived from a snapshot of the atom's value (via valueIO).

The computation is better run inside the swap operation for atomic consistency.

However, using writeIO is reasonable if this is simply a forceful overwrite of the atomic value without any dependency on the previous state.

Parameters

type A

Value type

param ma

Atom to write

returns

IO representation of the write operation

class Prelude Source #

Fields

field IO<CancellationToken> cancelToken = IO.lift(e => e.Token) Source #

Access the cancellation-token from the IO environment

Parameters

returns

CancellationToken

field IO<Unit> unitIO = IO<Unit>.Pure(default) Source #

Always yields a Unit value

field IO<EnvIO> envIO = IO<EnvIO>.Lift(e => e) Source #

Yields the IO environment

Methods

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

where M : Monad<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<IO, A> post <A> (K<IO, 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 IO<ForkIO<A>> fork <A> (K<IO, 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, ForkIO<A>> fork <M, A> (K<M, A> ma, Option<TimeSpan> timeout = default) Source #

where M : Monad<M>

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, ForkIO<Option<A>>> fork <M, A> (StreamT<M, A> ma, Option<TimeSpan> timeout = default) Source #

where M : Monad<M>

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 IO<ForkIO<Option<A>>> fork <A> (StreamT<IO, 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> awaitIO <M, A> (K<M, ForkIO<A>> ma) Source #

where M : Monad<M>

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 IO<A> awaitIO <A> (K<IO, ForkIO<A>> ma) 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 IO<Unit> yieldFor (Duration duration) Source #

Yield the thread for the specified duration or until cancelled.

Parameters

param duration

Amount of time to yield for

returns

Unit

method IO<Unit> yieldFor (TimeSpan timeSpan) Source #

Yield the thread for the specified duration or until cancelled.

Parameters

param timeSpan

Amount of time to yield for

returns

Unit

method K<M, Seq<A>> awaitAll <M, A> (params K<M, A>[] ms) Source #

where M : Monad<M>

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (params K<IO, A>[] ms) Source #

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (params IO<A>[] ms) Source #

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method K<M, Seq<A>> awaitAll <M, A> (params K<M, ForkIO<A>>[] forks) Source #

where M : Monad<M>

Awaits all forks

Parameters

param forks

Forks to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (params IO<ForkIO<A>>[] mfs) Source #

Awaits all

Parameters

param ms

IO operations to await

returns

Sequence of results

method K<M, Seq<A>> awaitAll <M, A> (Seq<K<M, A>> ms) Source #

where M : Monad<M>

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (Seq<K<IO, A>> ms) Source #

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (Seq<IO<A>> ms) Source #

Awaits all operations

Parameters

param ms

Operations to await

returns

Sequence of results

method K<M, Seq<A>> awaitAll <M, A> (Seq<K<M, ForkIO<A>>> forks) Source #

where M : Monad<M>

Awaits all forks

Parameters

param forks

Forks to await

returns

Sequence of results

method IO<Seq<A>> awaitAll <A> (Seq<IO<ForkIO<A>>> mfs) Source #

Awaits all

Parameters

param ms

IO operations to await

returns

Sequence of results

method K<M, A> awaitAny <M, A> (params K<M, A>[] forks) Source #

where M : Monad<M>

Awaits for any forks to complete

Parameters

param forks

Forks to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (params IO<A>[] ms) Source #

Awaits for any IO to complete

Parameters

param ms

IO operations to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (params K<IO, A>[] ms) Source #

Awaits for any IO to complete

Parameters

param ms

IO operations to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method K<M, A> awaitAny <M, A> (params K<M, ForkIO<A>>[] forks) Source #

where M : Monad<M>

Awaits for any forks to complete

Parameters

param forks

Forks to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (params IO<ForkIO<A>>[] forks) Source #

Awaits for any forks to complete

Parameters

param forks

Forks to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method K<M, A> awaitAny <M, A> (Seq<K<M, ForkIO<A>>> forks) Source #

where M : Monad<M>

Awaits for any forks to complete

Parameters

param forks

Forks to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method K<M, A> awaitAny <M, A> (Seq<K<M, A>> forks) Source #

where M : Monad<M>

Awaits for operations to complete

Parameters

param ms

Operations to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (Seq<K<IO, A>> ms) Source #

Awaits for any IO to complete

Parameters

param ms

IO operations to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (Seq<IO<A>> ms) Source #

Awaits for any IO to complete

Parameters

param ms

IO operations to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

method IO<A> awaitAny <A> (Seq<IO<ForkIO<A>>> mfs) Source #

Awaits for any forks to complete

Parameters

param forks

Forks to await

returns

If we get one success, then we'll return straight away and cancel the others. If we get any errors, we'll collect them in the hope that at least one works. If we have collected as many errors as we have forks, then we'll return them all.

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

where M : Monad<M>

Timeout operation if it takes too long

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

Timeout operation if it takes too long

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

where M : Monad<M>

Keeps repeating the computation

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

method IO<A> repeat <A> (IO<A> ma) Source #

Keeps repeating the computation

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps repeating the computation, until the scheduler expires

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

method IO<A> repeat <A> (Schedule schedule, K<IO, A> ma) Source #

Keeps repeating the computation, until the scheduler expires

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps repeating the computation until the predicate returns false

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

method IO<A> repeatWhile <A> (IO<A> ma, Func<A, bool> predicate) Source #

Keeps repeating the computation until the predicate returns false

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

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

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

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

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps repeating the computation until the predicate returns true

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

method IO<A> repeatUntil <A> ( K<IO, A> ma, Func<A, bool> predicate) Source #

Keeps repeating the computation until the predicate returns true

Parameters

type A

Computation bound value type

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

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

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

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

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for repeating

param ma

Computation to repeat

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

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

Keeps retrying the computation

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation, until the scheduler expires

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

method IO<A> retry <A> (Schedule schedule, K<IO, A> ma) Source #

Keeps retrying the computation, until the scheduler expires

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation until the predicate returns false

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

method IO<A> retryWhile <A> ( K<IO, A> ma, Func<Error, bool> predicate) Source #

Keeps retrying the computation until the predicate returns false

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation, until the scheduler expires, or the predicate returns false

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

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

Keeps retrying the computation, until the scheduler expires, or the predicate returns false

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation until the predicate returns true

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

method IO<A> retryUntil <A> ( K<IO, A> ma, Func<Error, bool> predicate) Source #

Keeps retrying the computation until the predicate returns true

Parameters

type A

Computation bound value type

param ma

Computation to retry

returns

The result of the last invocation of ma

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

where M : Monad<M>

Keeps retrying the computation, until the scheduler expires, or the predicate returns true

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

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

Keeps retrying the computation, until the scheduler expires, or the predicate returns true

Parameters

type A

Computation bound value type

param schedule

Scheduler strategy for retrying

param ma

Computation to retry

returns

The result of the last invocation of ma

class Prelude Source #

Methods

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

Functor map operation

Unwraps the value within the functor, passes it to the map function f provided, and then takes the mapped value and wraps it back up into a new functor.

Parameters

param ma

Functor to map

param f

Mapping function

returns

Mapped functor

method IO<B> action <A, B> (K<IO, A> ma, K<IO, B> mb) Source #

Applicative action: runs the first applicative, ignores the result, and returns the second applicative

method IO<B> apply <A, B> (K<IO, Func<A, B>> mf, K<IO, A> ma) Source #

Applicative functor apply operation

Unwraps the value within the ma applicative-functor, passes it to the unwrapped function(s) within mf, and then takes the resulting value and wraps it back up into a new applicative-functor.

Parameters

param ma

Value(s) applicative functor

param mf

Mapping function(s)

returns

Mapped applicative functor

class Resources Source #

Holds the acquired resources for the ResourceT monad transformer

Constructors

constructor Resources (Resources? parent) Source #

Methods

method IO<Resources> NewIO (Resources? parent) Source #

method void Dispose () Source #

method Unit DisposeU (EnvIO envIO) Source #

method Unit DisposeU () Source #

method IO<Unit> DisposeIO () Source #

method Unit Acquire <A> (A value) Source #

where A : IDisposable

method Unit AcquireAsync <A> (A value) Source #

where A : IAsyncDisposable

method Unit Acquire <A> (A value, Func<A, IO<Unit>> release) Source #

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

method IO<Unit> ReleaseAll () Source #