Contents
- EnvIO
- Resources
- Token
- Source
- SyncContext
- New ( Resources? resources = null, CancellationToken token = default, CancellationTokenSource? source = null, SynchronizationContext? syncContext = null)
- Local
- LocalResources
- LocalCancel
- LocalSyncContext
- Dispose ()
- ToString ()
- ForkIO <A> ( IO<Unit> Cancel, IO<A> Await)
- IO <A>
- Empty
- Map <B> (Func<A, B> f)
- ApplyBack <B> (K<IO, Func<A, B>> f)
- Map <B> (B value)
- MapFail (Func<Error, Error> f)
- BiMap <B> (Func<A, B> Succ, Func<Error, Error> Fail)
- Match <B> (Func<A, B> Succ, Func<Error, B> Fail)
- IfFail (Func<Error, A> Fail)
- IfFail (A Fail)
- IfFail (Func<Error, IO<A>> Fail)
- IfFail (IO<A> Fail)
- Fold <S> ( Schedule schedule, S initialState, Func<S, A, S> folder)
- Fold <S> ( S initialState, Func<S, A, S> folder)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- Post ()
- Bind <B> (Func<A, K<IO, B>> f)
- BindAsync <B> (Func<A, ValueTask<K<IO, B>>> f)
- Bind <B> (Func<A, IO<B>> f)
- Bind <B> (Func<A, Pure<B>> f)
- Bind <M, B> (Func<A, K<M, B>> f)
- BindAsync <B> (Func<A, ValueTask<IO<B>>> f)
- BindAsync <M, B> (Func<A, ValueTask<K<M, B>>> f)
- Select <B> (Func<A, B> f)
- SelectMany <B, C> (Func<A, IO<B>> bind, Func<A, B, C> project)
- SelectMany <B, C> (Func<A, K<IO, B>> bind, Func<A, B, C> project)
- SelectMany <B, C> (Func<A, Pure<B>> bind, Func<A, B, C> project)
- SelectMany <B, C> (Func<A, Eff<B>> bind, Func<A, B, C> project)
- SelectMany <RT, B, C> (Func<A, Eff<RT, B>> bind, Func<A, B, C> project)
- SelectMany <C> (Func<A, Guard<Error, Unit>> bind, Func<A, Unit, C> project)
- Bracket ()
- BracketFail ()
- Bracket <B, C> (Func<A, IO<C>> Use, Func<A, IO<B>> Fin)
- Bracket <B, C> (Func<A, IO<C>> Use, Func<Error, IO<C>> Catch, Func<A, IO<B>> Fin)
- Timeout (TimeSpan timeout)
- Local ()
- Fork (Option<TimeSpan> timeout = default)
- Try ()
- Repeat ()
- Repeat (Schedule schedule)
- RepeatWhile (Func<A, bool> predicate)
- RepeatWhile ( Schedule schedule, Func<A, bool> predicate)
- RepeatUntil (Func<A, bool> predicate)
- RepeatUntil ( Schedule schedule, Func<A, bool> predicate)
- Retry ()
- Retry (Schedule schedule)
- RetryWhile (Func<Error, bool> predicate)
- RetryWhile ( Schedule schedule, Func<Error, bool> predicate)
- RetryUntil (Func<Error, bool> predicate)
- RetryUntil (Schedule schedule, Func<Error, bool> predicate)
- Catch (Func<Error, bool> Predicate, Func<Error, K<IO, A>> Fail)
- Finally <X> (K<IO, X> @finally)
- Combine (IO<A> rhs)
- Run ()
- Run (EnvIO envIO)
- RunAsync ()
- RunAsync (EnvIO envIO)
- ToString ()
- IO
- pure <A> (A value)
- fail <A> (Error value)
- fail <A> (string value)
- lift (Action f)
- lift <A> (Either<Error, A> ma)
- lift <A> (Fin<A> ma)
- lift <A> (Func<A> f)
- lift <A> (Func<EnvIO, A> f)
- lift <A> (Func<Fin<A>> f)
- lift <A> (Func<EnvIO, Fin<A>> f)
- lift <A> (Func<Either<Error, A>> f)
- lift <A> (Func<EnvIO, Either<Error, A>> f)
- liftAsync <A> (Func<Task<A>> f)
- liftAsync <A> (Func<EnvIO, Task<A>> f)
- liftVAsync <A> (Func<ValueTask<A>> f)
- liftVAsync <A> (Func<EnvIO, ValueTask<A>> f)
- local <M, A> (K<M, A> ma)
- local <A> (K<IO, A> ma)
- env = lift(e => e)
- token = new IOToken<CancellationToken>(pure)
- source = lift(e => e.Source)
- syncContext = lift(e => Optional(e.SyncContext))
- empty <A> ()
- combine <A> (K<IO, A> ma, K<IO, A> mb)
- mapIO <M, A, B> (K<M, A> ma, Func<IO<A>, IO<B>> f)
- fork <M, A> (K<M, A> ma, Option<TimeSpan> timeout = default)
- yieldFor (Duration duration)
- yieldFor (TimeSpan timeSpan)
- IO
- Resources
Sub modules
| DSL |
| Extensions |
| Operators |
| Prelude |
Environment for the IO monad
Fields
field SynchronizationContext? SyncContext Source #
Properties
property EnvIO LocalResources Source #
property EnvIO LocalCancel Source #
property EnvIO LocalSyncContext 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 |
| param | Await | An |
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.
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 |
Methods
method IO<S> FoldWhile <S> ( Schedule schedule, 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> ( 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> ( 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<(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 #
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<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 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<A> BracketFail () Source #
The IO monad tracks resources automatically, this creates a local resource environment to run this computation in. If the computation errors then the resources are automatically released.
This differs from Bracket in that Bracket will also free resources once the computation
is successfully complete. BracketFail only frees resources on failure.
method IO<C> Bracket <B, C> (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 | Use | Function to use the acquired resource |
| param | Fin | 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>> 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 | 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 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<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 |
| |
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 |
| 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 |
| 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 |
| 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 |
| 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> Finally <X> (K<IO, X> @finally) Source #
Run a finally operation after the this operation regardless of whether this succeeds or not.
Parameters
| param | finally | Finally operation |
| returns | Result of primary operation | |
method IO<A> Combine (IO<A> rhs) Source #
Monoid combine
Parameters
| param | rhs | Alternative |
| returns | This if computation runs without error. | |
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 A Run (EnvIO envIO) 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 ValueTask<A> RunAsync () 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 ValueTask<A> RunAsync (EnvIO envIO) 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 | |
Fields
field IO<EnvIO> env = lift(e => e) Source #
field IO<CancellationToken> token = new IOToken<CancellationToken>(pure) 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> pure <A> (A value) Source #
Lift a pure value into an IO computation
Parameters
| type | A | Bound value type |
| param | value | value |
| returns | IO in a success state. Always yields the lifted value. | |
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 IO<A> liftVAsync <A> (Func<ValueTask<A>> f) Source #
method IO<A> liftVAsync <A> (Func<EnvIO, ValueTask<A>> f) Source #
method K<M, A> local <M, 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 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 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, B> mapIO <M, A, B> (K<M, A> ma, Func<IO<A>, IO<B>> f) Source #
Queue this IO operation to run on the thread-pool.
Parameters
| param | timeout | Maximum time that the forked IO operation can run for. |
| returns | Returns a | |
method K<M, ForkIO<A>> fork <M, 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. |
| returns | Returns a | |
Holds the acquired resources for the ResourceT monad transformer
Methods
method IO<Unit> ReleaseAll () Source #