Table of Contents

Class ResultExtension

Namespace
Arc4u.Results
Assembly
Arc4u.Results.dll

Reads a use case out loud: OnSuccess / OnSuccessNull / OnSuccessNotNull / OnFailed describe what happens to a FluentResults.Result without the caller writing a single if statement.

Two rules keep that readability honest:

  1. A method named *Async always returns a Task or a ValueTask, so the caller must await it. Nothing in this class ever blocks on a Task (no .Wait(), no .Result).
  2. A method NOT named *Async never accepts an asynchronous callback. Passing one is a compile error pointing at the *Async twin, because an async lambda bound to an Action would run as 'async void': fire-and-forget, with nothing awaiting it. Its exception would then surface on a thread pool thread instead of at the caller's await.
  3. OnSuccess / OnSuccessNull / OnSuccessNotNull / OnFailed run an action and return the original result unchanged, so they never accept a callback returning a result, whose errors would be discarded. Passing one is a compile error pointing at the steps that can fail: Then, EnsureNotNull, Ensure, Compensate and Recover.

The *Async twins take Task-returning callbacks. Adapt a ValueTask-returning call with an async lambda ('async () => await SaveAsync()') or with .AsTask(): a second overload taking Func<ValueTask> would make every async lambda ambiguous.

None of these methods turns an exception thrown by a callback into a failed Result: the exception propagates to the caller. Use FluentResults' Result.Try for that conversion.

public static class ResultExtension
Inheritance
ResultExtension
Inherited Members

Examples

Task<Result<Order>> GetOrderAsync(int id) => ...;

var globalResult = Result.Ok();

var result = await GetOrderAsync(42)
    .OnSuccessNotNull(order => Console.WriteLine($"Order {order.Id} found"))
    .OnSuccessNull(() => Console.WriteLine("No such order"))
    .OnFailed(globalResult)
    .LogIfFailed();

Methods

Compensate(Result, Func<IReadOnlyCollection<IError>, IResultBase>)

Runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Result Compensate(this Result result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result Result

The result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

Result

A new failed result with the reasons of both, or result when it succeeded.

Remarks

A successful result is returned unchanged and compensation is not called. Otherwise the new result carries the reasons of result followed by those of the clean-up, so it stays failed whatever the clean-up returns, and an error of the clean-up is not lost. Use Recover to replace the failure instead. An exception thrown by the clean-up propagates to the caller.

Exceptions

ArgumentNullException

compensation is null.

Compensate(Task<Result>, Func<IReadOnlyCollection<IError>, IResultBase>)

Awaits the task, then runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result> Compensate(this Task<Result> result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result Task<Result>

The task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

Task<Result>

A task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Remarks

Exceptions

ArgumentNullException

compensation is null.

Compensate(ValueTask<Result>, Func<IReadOnlyCollection<IError>, IResultBase>)

Awaits the value task, then runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static ValueTask<Result> Compensate(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TResult>(Result, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result> CompensateAsync<TResult>(this Result result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result Result

The result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

Task<Result>

A task completing with a new failed result with the reasons of both, or with result when it succeeded.

Type Parameters

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TResult>(Task<Result>, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits the task, then awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result> CompensateAsync<TResult>(this Task<Result> result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result Task<Result>

The task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

Task<Result>

A task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TResult>(ValueTask<Result>, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits the value task, then awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static ValueTask<Result> CompensateAsync<TResult>(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TValue, TResult>(Result<TValue>, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result<TValue>> CompensateAsync<TValue, TResult>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result Result<TValue>

The result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with a new failed result with the reasons of both, or with result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TValue, TResult>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits the task, then awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result<TValue>> CompensateAsync<TValue, TResult>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

CompensateAsync<TValue, TResult>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task<TResult>>)

Awaits the value task, then awaits an asynchronous clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static ValueTask<Result<TValue>> CompensateAsync<TValue, TResult>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task<TResult>> compensation) where TResult : IResultBase

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, Task<TResult>>

The clean-up receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the clean-up.

Remarks

Exceptions

ArgumentNullException

compensation is null.

Compensate<TValue>(Result<TValue>, Func<IReadOnlyCollection<IError>, IResultBase>)

Runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Result<TValue> Compensate<TValue>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result Result<TValue>

The result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

Result<TValue>

A new failed result with the reasons of both, or result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

compensation is null.

Compensate<TValue>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, IResultBase>)

Awaits the task, then runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static Task<Result<TValue>> Compensate<TValue>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

compensation is null.

Compensate<TValue>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, IResultBase>)

Awaits the value task, then runs a clean-up that can fail when the result is failed, and adds its reasons to the failure.

public static ValueTask<Result<TValue>> Compensate<TValue>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, IResultBase> compensation)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

compensation Func<IReadOnlyCollection<IError>, IResultBase>

The clean-up receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with a new failed result with the reasons of both, or with the awaited result when it succeeded.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

compensation is null.

EnsureAsync<TValue, TResult>(Result<TValue>, Func<TValue, Task<TResult>>)

Awaits an asynchronous step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static Task<Result<TValue>> EnsureAsync<TValue, TResult>(this Result<TValue> result, Func<TValue, Task<TResult>> step) where TResult : IResultBase

Parameters

result Result<TValue>

The result to inspect.

step Func<TValue, Task<TResult>>

The step receiving the value.

Returns

Task<Result<TValue>>

A task completing with a new result with the value and the reasons of both, or with result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the step.

Remarks

Exceptions

ArgumentNullException

step is null.

EnsureAsync<TValue, TResult>(Task<Result<TValue>>, Func<TValue, Task<TResult>>)

Awaits the task, then awaits an asynchronous step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static Task<Result<TValue>> EnsureAsync<TValue, TResult>(this Task<Result<TValue>> result, Func<TValue, Task<TResult>> step) where TResult : IResultBase

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

step Func<TValue, Task<TResult>>

The step receiving the value.

Returns

Task<Result<TValue>>

A task completing with a new result with the value and the reasons of both, or with the awaited result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the step.

Remarks

Exceptions

ArgumentNullException

step is null.

EnsureAsync<TValue, TResult>(ValueTask<Result<TValue>>, Func<TValue, Task<TResult>>)

Awaits the value task, then awaits an asynchronous step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static ValueTask<Result<TValue>> EnsureAsync<TValue, TResult>(this ValueTask<Result<TValue>> result, Func<TValue, Task<TResult>> step) where TResult : IResultBase

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

step Func<TValue, Task<TResult>>

The step receiving the value.

Returns

ValueTask<Result<TValue>>

A value task completing with a new result with the value and the reasons of both, or with the awaited result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

TResult

The type of the result produced by the step.

Remarks

Exceptions

ArgumentNullException

step is null.

EnsureNotNull<TValue>(Result<TValue?>, Func<IError>)

Turns a successful result whose value is null into a failed result carrying the error built by error.

public static Result<TValue> EnsureNotNull<TValue>(this Result<TValue?> result, Func<IError> error)

Parameters

result Result<TValue>

The result to inspect.

error Func<IError>

Builds the error when the value is null; it is only called in that case.

Returns

Result<TValue>

A new result with the value of result, or failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

A failed result keeps its errors and error is not called. A successful result with a value keeps it, now typed as not null. The reasons of the original result are always kept. A nullable value type is returned as is, still typed as nullable.

Exceptions

ArgumentNullException

error is null.

EnsureNotNull<TValue>(Task<Result<TValue?>>, Func<IError>)

Awaits the task, then turns a successful result whose value is null into a failed result carrying the error built by error.

public static Task<Result<TValue>> EnsureNotNull<TValue>(this Task<Result<TValue?>> result, Func<IError> error)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

error Func<IError>

Builds the error when the value is null; it is only called in that case.

Returns

Task<Result<TValue>>

A task completing with a new result with the value of the awaited result, or failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

error is null.

EnsureNotNull<TValue>(ValueTask<Result<TValue?>>, Func<IError>)

Awaits the value task, then turns a successful result whose value is null into a failed result carrying the error built by error.

public static ValueTask<Result<TValue>> EnsureNotNull<TValue>(this ValueTask<Result<TValue?>> result, Func<IError> error)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

error Func<IError>

Builds the error when the value is null; it is only called in that case.

Returns

ValueTask<Result<TValue>>

A value task completing with a new result with the value of the awaited result, or failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

error is null.

Ensure<TValue>(Result<TValue>, Func<TValue, IResultBase>)

Runs a step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static Result<TValue> Ensure<TValue>(this Result<TValue> result, Func<TValue, IResultBase> step)

Parameters

result Result<TValue>

The result to inspect.

step Func<TValue, IResultBase>

The step receiving the value.

Returns

Result<TValue>

A new result with the value of result and the reasons of both, or result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

A failed result is returned unchanged and step is not called. Otherwise the new result carries the reasons of result followed by those of the step: it fails with the errors of the step, or succeeds with the original value. The value of a result returned by the step is ignored; use Then to continue with it. An exception thrown by the step propagates to the caller.

Exceptions

ArgumentNullException

step is null.

Ensure<TValue>(Task<Result<TValue>>, Func<TValue, IResultBase>)

Awaits the task, then runs a step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static Task<Result<TValue>> Ensure<TValue>(this Task<Result<TValue>> result, Func<TValue, IResultBase> step)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

step Func<TValue, IResultBase>

The step receiving the value.

Returns

Task<Result<TValue>>

A task completing with a new result with the value and the reasons of both, or with the awaited result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

step is null.

Ensure<TValue>(ValueTask<Result<TValue>>, Func<TValue, IResultBase>)

Awaits the value task, then runs a step that can fail on the value of a successful result, and keeps the value when the step succeeds.

public static ValueTask<Result<TValue>> Ensure<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, IResultBase> step)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

step Func<TValue, IResultBase>

The step receiving the value.

Returns

ValueTask<Result<TValue>>

A value task completing with a new result with the value and the reasons of both, or with the awaited result when it failed.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

step is null.

LogIfFailed(Task<Result>, LogLevel)

Awaits the task, then passes the result and logLevel to the FluentResults logger when the result is failed.

public static Task<Result> LogIfFailed(this Task<Result> result, LogLevel logLevel = LogLevel.Error)

Parameters

result Task<Result>

The task producing the result to inspect.

logLevel LogLevel

The level handed to the result logger. Defaults to Error.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.

LogIfFailed(ValueTask<Result>, LogLevel)

Awaits the value task, then passes the result and logLevel to the FluentResults logger when the result is failed.

public static ValueTask<Result> LogIfFailed(this ValueTask<Result> result, LogLevel logLevel = LogLevel.Error)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

logLevel LogLevel

The level handed to the result logger. Defaults to Error.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.

LogIfFailed<TValue>(Task<Result<TValue>>, LogLevel)

Awaits the task, then passes the result and logLevel to the FluentResults logger when the result is failed.

public static Task<Result<TValue>> LogIfFailed<TValue>(this Task<Result<TValue>> result, LogLevel logLevel = LogLevel.Error)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

logLevel LogLevel

The level handed to the result logger. Defaults to Error.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.

LogIfFailed<TValue>(ValueTask<Result<TValue>>, LogLevel)

Awaits the value task, then passes the result and logLevel to the FluentResults logger when the result is failed.

public static ValueTask<Result<TValue>> LogIfFailed<TValue>(this ValueTask<Result<TValue>> result, LogLevel logLevel = LogLevel.Error)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

logLevel LogLevel

The level handed to the result logger. Defaults to Error.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.

MatchAsync<TOut>(Result, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the callback matching the state of the result and returns what it produces.

public static Task<TOut> MatchAsync<TOut>(this Result result, Func<Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Result

The result to match.

onSuccess Func<Task<TOut>>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TOut>(Task<Result>, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the task, then awaits the callback matching the state of the result and returns what it produces.

public static Task<TOut> MatchAsync<TOut>(this Task<Result> result, Func<Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Task<Result>

The task producing the result to match.

onSuccess Func<Task<TOut>>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TOut>(ValueTask<Result>, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the value task, then awaits the callback matching the state of the result and returns what it produces.

public static ValueTask<TOut> MatchAsync<TOut>(this ValueTask<Result> result, Func<Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result ValueTask<Result>

The value task producing the result to match.

onSuccess Func<Task<TOut>>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TValue, TOut>(Result<TValue>, Func<TValue, Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the callback matching the state of the result and returns what it produces.

public static Task<TOut> MatchAsync<TValue, TOut>(this Result<TValue> result, Func<TValue, Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Result<TValue>

The result to match.

onSuccess Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TValue, TOut>(Result<TValue?>, Func<TValue, Task<TOut>>, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static Task<TOut> MatchAsync<TValue, TOut>(this Result<TValue?> result, Func<TValue, Task<TOut>> onSuccessNotNull, Func<Task<TOut>> onSuccessNull, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Result<TValue>

The result to match.

onSuccessNotNull Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<Task<TOut>>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

MatchAsync<TValue, TOut>(Task<Result<TValue>>, Func<TValue, Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the task, then awaits the callback matching the state of the result and returns what it produces.

public static Task<TOut> MatchAsync<TValue, TOut>(this Task<Result<TValue>> result, Func<TValue, Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Task<Result<TValue>>

The task producing the result to match.

onSuccess Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TValue, TOut>(Task<Result<TValue?>>, Func<TValue, Task<TOut>>, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the task, then awaits the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static Task<TOut> MatchAsync<TValue, TOut>(this Task<Result<TValue?>> result, Func<TValue, Task<TOut>> onSuccessNotNull, Func<Task<TOut>> onSuccessNull, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result Task<Result<TValue>>

The task producing the result to match.

onSuccessNotNull Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<Task<TOut>>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

MatchAsync<TValue, TOut>(ValueTask<Result<TValue>>, Func<TValue, Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the value task, then awaits the callback matching the state of the result and returns what it produces.

public static ValueTask<TOut> MatchAsync<TValue, TOut>(this ValueTask<Result<TValue>> result, Func<TValue, Task<TOut>> onSuccess, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to match.

onSuccess Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

MatchAsync<TValue, TOut>(ValueTask<Result<TValue?>>, Func<TValue, Task<TOut>>, Func<Task<TOut>>, Func<IReadOnlyCollection<IError>, Task<TOut>>)

Awaits the value task, then awaits the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static ValueTask<TOut> MatchAsync<TValue, TOut>(this ValueTask<Result<TValue?>> result, Func<TValue, Task<TOut>> onSuccessNotNull, Func<Task<TOut>> onSuccessNull, Func<IReadOnlyCollection<IError>, Task<TOut>> onFailed)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to match.

onSuccessNotNull Func<TValue, Task<TOut>>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<Task<TOut>>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, Task<TOut>>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

Match<TOut>(Result, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Calls the callback matching the state of the result and returns what it produces.

public static TOut Match<TOut>(this Result result, Func<TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Result

The result to match.

onSuccess Func<TOut>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

TOut

The value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Ends a chain by turning the result into another type, for instance an HTTP response or a message for the user. Exactly one callback is called. Unlike OnSuccess and OnFailed, the callbacks produce the value returned by the method, so no variable needs to be assigned from a callback. An exception thrown by a callback propagates to the caller.

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TOut>(Task<Result>, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the task, then calls the callback matching the state of the result and returns what it produces.

public static Task<TOut> Match<TOut>(this Task<Result> result, Func<TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Task<Result>

The task producing the result to match.

onSuccess Func<TOut>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TOut>(ValueTask<Result>, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the value task, then calls the callback matching the state of the result and returns what it produces.

public static ValueTask<TOut> Match<TOut>(this ValueTask<Result> result, Func<TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result ValueTask<Result>

The value task producing the result to match.

onSuccess Func<TOut>

Produces the outcome of a successful result.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TValue, TOut>(Result<TValue>, Func<TValue, TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Calls the callback matching the state of the result and returns what it produces.

public static TOut Match<TValue, TOut>(this Result<TValue> result, Func<TValue, TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Result<TValue>

The result to match.

onSuccess Func<TValue, TOut>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

TOut

The value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TValue, TOut>(Result<TValue?>, Func<TValue, TOut>, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Calls the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static TOut Match<TValue, TOut>(this Result<TValue?> result, Func<TValue, TOut> onSuccessNotNull, Func<TOut> onSuccessNull, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Result<TValue>

The result to match.

onSuccessNotNull Func<TValue, TOut>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<TOut>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

TOut

The value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Meant for a result whose value is declared nullable, such as Result<Order?>: onSuccessNotNull then receives a value that is not null. For a value declared not nullable, use the overload with a single success callback. See Match<TOut>(Result, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>).

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

Match<TValue, TOut>(Task<Result<TValue>>, Func<TValue, TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the task, then calls the callback matching the state of the result and returns what it produces.

public static Task<TOut> Match<TValue, TOut>(this Task<Result<TValue>> result, Func<TValue, TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Task<Result<TValue>>

The task producing the result to match.

onSuccess Func<TValue, TOut>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TValue, TOut>(Task<Result<TValue?>>, Func<TValue, TOut>, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the task, then calls the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static Task<TOut> Match<TValue, TOut>(this Task<Result<TValue?>> result, Func<TValue, TOut> onSuccessNotNull, Func<TOut> onSuccessNull, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result Task<Result<TValue>>

The task producing the result to match.

onSuccessNotNull Func<TValue, TOut>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<TOut>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

Task<TOut>

A task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

Match<TValue, TOut>(ValueTask<Result<TValue>>, Func<TValue, TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the value task, then calls the callback matching the state of the result and returns what it produces.

public static ValueTask<TOut> Match<TValue, TOut>(this ValueTask<Result<TValue>> result, Func<TValue, TOut> onSuccess, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to match.

onSuccess Func<TValue, TOut>

Produces the outcome of a successful result from its value, which can be null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

onSuccess or onFailed is null.

Match<TValue, TOut>(ValueTask<Result<TValue?>>, Func<TValue, TOut>, Func<TOut>, Func<IReadOnlyCollection<IError>, TOut>)

Awaits the value task, then calls the callback matching the state of the result, telling a successful result with a value from one whose value is null, and returns what it produces.

public static ValueTask<TOut> Match<TValue, TOut>(this ValueTask<Result<TValue?>> result, Func<TValue, TOut> onSuccessNotNull, Func<TOut> onSuccessNull, Func<IReadOnlyCollection<IError>, TOut> onFailed)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to match.

onSuccessNotNull Func<TValue, TOut>

Produces the outcome of a successful result from its value, which is not null.

onSuccessNull Func<TOut>

Produces the outcome of a successful result whose value is null.

onFailed Func<IReadOnlyCollection<IError>, TOut>

Produces the outcome of a failed result from its errors.

Returns

ValueTask<TOut>

A value task completing with the value produced by the callback that was called.

Type Parameters

TValue

The type of the value carried by the result.

TOut

The type produced by the callbacks.

Remarks

Exceptions

ArgumentNullException

One of onSuccessNotNull, onSuccessNull, onFailed is null.

OnFailed(Result, Result)

Copies the errors of the result into globalResult when the result is failed.

public static Result OnFailed(this Result result, Result globalResult)

Parameters

result Result

The result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

Result

The result received, unchanged.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed(Result, Action<IReadOnlyCollection<IError>>)

Invokes the callback with the errors of the result when the result is failed.

public static Result OnFailed(this Result result, Action<IReadOnlyCollection<IError>> action)

Parameters

result Result

The result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

Result

The result received, unchanged.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailed(Task<Result>, Result)

Awaits the task, then copies the errors of the result into globalResult when the result is failed.

public static Task<Result> OnFailed(this Task<Result> result, Result globalResult)

Parameters

result Task<Result>

The task producing the result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed(Task<Result>, Action<IReadOnlyCollection<IError>>)

Awaits the task, then invokes the callback with the errors of the result when the result is failed.

public static Task<Result> OnFailed(this Task<Result> result, Action<IReadOnlyCollection<IError>> action)

Parameters

result Task<Result>

The task producing the result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailed(ValueTask<Result>, Result)

Awaits the value task, then copies the errors of the result into globalResult when the result is failed.

public static ValueTask<Result> OnFailed(this ValueTask<Result> result, Result globalResult)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed(ValueTask<Result>, Action<IReadOnlyCollection<IError>>)

Awaits the value task, then invokes the callback with the errors of the result when the result is failed.

public static ValueTask<Result> OnFailed(this ValueTask<Result> result, Action<IReadOnlyCollection<IError>> action)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailedAsync(Result, Func<IReadOnlyCollection<IError>, Task>)

Awaits the asynchronous callback with the errors of the result when the result is failed.

public static Task<Result> OnFailedAsync(this Result result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result Result

The result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with the result received, unchanged, once the callback has run.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailedAsync(Task<Result>, Func<IReadOnlyCollection<IError>, Task>)

Awaits the task, then awaits the asynchronous callback with the errors of the result when the result is failed.

public static Task<Result> OnFailedAsync(this Task<Result> result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result Task<Result>

The task producing the result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailedAsync(ValueTask<Result>, Func<IReadOnlyCollection<IError>, Task>)

Awaits the value task, then awaits the asynchronous callback with the errors of the result when the result is failed.

public static ValueTask<Result> OnFailedAsync(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailedAsync<TValue>(Result<TValue>, Func<IReadOnlyCollection<IError>, Task>)

Awaits the asynchronous callback with the errors of the result when the result is failed.

public static Task<Result<TValue>> OnFailedAsync<TValue>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailedAsync<TValue>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task>)

Awaits the task, then awaits the asynchronous callback with the errors of the result when the result is failed.

public static Task<Result<TValue>> OnFailedAsync<TValue>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailedAsync<TValue>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task>)

Awaits the value task, then awaits the asynchronous callback with the errors of the result when the result is failed.

public static ValueTask<Result<TValue>> OnFailedAsync<TValue>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<IReadOnlyCollection<IError>, Task>

The callback receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnFailed<TGlobal>(Result, Result<TGlobal>)

Collects the errors of an untyped result into a typed global one, the synchronous twin of OnFailed<TGlobal>(Task<Result>, Result<TGlobal>).

public static Result OnFailed<TGlobal>(this Result result, Result<TGlobal> globalResult)

Parameters

result Result

The result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

Result

The result received, unchanged.

Type Parameters

TGlobal

The type of the value carried by the global result.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue>(Result<TValue>, Result)

Collects the errors of a typed result into an untyped global one, the synchronous twin of OnFailed<TValue>(Task<Result<TValue>>, Result).

public static Result<TValue> OnFailed<TValue>(this Result<TValue> result, Result globalResult)

Parameters

result Result<TValue>

The result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue>(Result<TValue>, Action<IReadOnlyCollection<IError>>)

Invokes the callback with the errors of the result when the result is failed.

public static Result<TValue> OnFailed<TValue>(this Result<TValue> result, Action<IReadOnlyCollection<IError>> action)

Parameters

result Result<TValue>

The result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailed<TValue>(Task<Result<TValue>>, Result)

Awaits the task, then copies the errors of the result into globalResult when the result is failed.

public static Task<Result<TValue>> OnFailed<TValue>(this Task<Result<TValue>> result, Result globalResult)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue>(Task<Result<TValue>>, Action<IReadOnlyCollection<IError>>)

Awaits the task, then invokes the callback with the errors of the result when the result is failed.

public static Task<Result<TValue>> OnFailed<TValue>(this Task<Result<TValue>> result, Action<IReadOnlyCollection<IError>> action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailed<TGlobal>(Task<Result>, Result<TGlobal>)

Awaits the task, then copies the errors of the result into globalResult when the result is failed.

public static Task<Result> OnFailed<TGlobal>(this Task<Result> result, Result<TGlobal> globalResult)

Parameters

result Task<Result>

The task producing the result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Type Parameters

TGlobal

The type of the value carried by the global result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue>(ValueTask<Result<TValue>>, Result)

Awaits the value task, then copies the errors of the result into globalResult when the result is failed.

public static ValueTask<Result<TValue>> OnFailed<TValue>(this ValueTask<Result<TValue>> result, Result globalResult)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

globalResult Result

The result that collects the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue>(ValueTask<Result<TValue>>, Action<IReadOnlyCollection<IError>>)

Awaits the value task, then invokes the callback with the errors of the result when the result is failed.

public static ValueTask<Result<TValue>> OnFailed<TValue>(this ValueTask<Result<TValue>> result, Action<IReadOnlyCollection<IError>> action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action<IReadOnlyCollection<IError>>

The callback receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnFailed<TGlobal>(ValueTask<Result>, Result<TGlobal>)

Collects the errors of an untyped result into a typed global one, the ValueTask twin of OnFailed<TGlobal>(Task<Result>, Result<TGlobal>).

public static ValueTask<Result> OnFailed<TGlobal>(this ValueTask<Result> result, Result<TGlobal> globalResult)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Type Parameters

TGlobal

The type of the value carried by the global result.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue, TGlobal>(Result<TValue>, Result<TGlobal>)

Copies the errors of the result into globalResult when the result is failed.

public static Result<TValue> OnFailed<TValue, TGlobal>(this Result<TValue> result, Result<TGlobal> globalResult)

Parameters

result Result<TValue>

The result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

TGlobal

The type of the value carried by the global result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue, TGlobal>(Task<Result<TValue>>, Result<TGlobal>)

Awaits the task, then copies the errors of the result into globalResult when the result is failed.

public static Task<Result<TValue>> OnFailed<TValue, TGlobal>(this Task<Result<TValue>> result, Result<TGlobal> globalResult)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

TGlobal

The type of the value carried by the global result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnFailed<TValue, TGlobal>(ValueTask<Result<TValue>>, Result<TGlobal>)

Awaits the value task, then copies the errors of the result into globalResult when the result is failed.

public static ValueTask<Result<TValue>> OnFailed<TValue, TGlobal>(this ValueTask<Result<TValue>> result, Result<TGlobal> globalResult)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

globalResult Result<TGlobal>

The result that collects the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

TGlobal

The type of the value carried by the global result.

Remarks

Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.

Exceptions

ArgumentNullException

globalResult is null.

OnSuccess(Result, Action)

Invokes the callback only when the result is successful.

public static Result OnSuccess(this Result result, Action action)

Parameters

result Result

The result to inspect.

action Action

The callback to run.

Returns

Result

The result received, unchanged.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess(Task<Result>, Action)

Awaits the task, then invokes the callback only when the result is successful.

public static Task<Result> OnSuccess(this Task<Result> result, Action action)

Parameters

result Task<Result>

The task producing the result to inspect.

action Action

The callback to run.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess(ValueTask<Result>, Action)

Awaits the value task, then invokes the callback only when the result is successful.

public static ValueTask<Result> OnSuccess(this ValueTask<Result> result, Action action)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

action Action

The callback to run.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessAsync(Result, Func<Task>)

Awaits the asynchronous callback only when the result is successful.

public static Task<Result> OnSuccessAsync(this Result result, Func<Task> func)

Parameters

result Result

The result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result>

A task completing with the result received, unchanged, once the callback has run.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync(Task<Result>, Func<Task>)

Awaits the task, then awaits the asynchronous callback only when the result is successful.

public static Task<Result> OnSuccessAsync(this Task<Result> result, Func<Task> func)

Parameters

result Task<Result>

The task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result>

A task completing with the awaited result, unchanged.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync(ValueTask<Result>, Func<Task>)

Awaits the value task, then awaits the asynchronous callback only when the result is successful.

public static ValueTask<Result> OnSuccessAsync(this ValueTask<Result> result, Func<Task> func)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

ValueTask<Result>

A value task completing with the awaited result, unchanged.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(Result<TValue>, Func<Task>)

Awaits the asynchronous callback only when the result is successful.

public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Result<TValue> result, Func<Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(Result<TValue>, Func<TValue, Task>)

Awaits the asynchronous callback, passing it the value of the result only when the result is successful.

public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Result<TValue> result, Func<TValue, Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(Task<Result<TValue>>, Func<Task>)

Awaits the task, then awaits the asynchronous callback only when the result is successful.

public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task>)

Awaits the task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful.

public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Task<Result<TValue>> result, Func<TValue, Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)

Awaits the value task, then awaits the asynchronous callback only when the result is successful.

public static ValueTask<Result<TValue>> OnSuccessAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Task>)

Awaits the value task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful.

public static ValueTask<Result<TValue>> OnSuccessAsync<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(Result<TValue>, Func<Task>)

Awaits the asynchronous callback only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Result<TValue> result, Func<Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(Result<TValue>, Func<TValue, Task>)

Awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Result<TValue> result, Func<TValue, Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(Task<Result<TValue>>, Func<Task>)

Awaits the task, then awaits the asynchronous callback only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task>)

Awaits the task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Task<Result<TValue>> result, Func<TValue, Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)

Awaits the value task, then awaits the asynchronous callback only when the result is successful and its value is not null.

public static ValueTask<Result<TValue>> OnSuccessNotNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNullAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Task>)

Awaits the value task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.

public static ValueTask<Result<TValue>> OnSuccessNotNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<TValue, Task>

The callback receiving the value of the result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNotNull<TValue>(Result<TValue>, Action)

Invokes the callback only when the result is successful and its value is not null.

public static Result<TValue> OnSuccessNotNull<TValue>(this Result<TValue> result, Action action)

Parameters

result Result<TValue>

The result to inspect.

action Action

The callback to run.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNotNull<TValue>(Result<TValue>, Action<TValue>)

Invokes the callback with the value of the result only when the result is successful and its value is not null.

public static Result<TValue> OnSuccessNotNull<TValue>(this Result<TValue> result, Action<TValue> action)

Parameters

result Result<TValue>

The result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNotNull<TValue>(Task<Result<TValue>>, Action)

Awaits the task, then invokes the callback only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNull<TValue>(this Task<Result<TValue>> result, Action action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNotNull<TValue>(Task<Result<TValue>>, Action<TValue>)

Awaits the task, then invokes the callback with the value of the result only when the result is successful and its value is not null.

public static Task<Result<TValue>> OnSuccessNotNull<TValue>(this Task<Result<TValue>> result, Action<TValue> action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNotNull<TValue>(ValueTask<Result<TValue>>, Action)

Awaits the value task, then invokes the callback only when the result is successful and its value is not null.

public static ValueTask<Result<TValue>> OnSuccessNotNull<TValue>(this ValueTask<Result<TValue>> result, Action action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNotNull<TValue>(ValueTask<Result<TValue>>, Action<TValue>)

Awaits the value task, then invokes the callback with the value of the result only when the result is successful and its value is not null.

public static ValueTask<Result<TValue>> OnSuccessNotNull<TValue>(this ValueTask<Result<TValue>> result, Action<TValue> action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNullAsync<TValue>(Result<TValue>, Func<Task>)

Awaits the asynchronous callback only when the result is successful and its value is null.

public static Task<Result<TValue>> OnSuccessNullAsync<TValue>(this Result<TValue> result, Func<Task> func)

Parameters

result Result<TValue>

The result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the result received, unchanged, once the callback has run.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNullAsync<TValue>(Task<Result<TValue>>, Func<Task>)

Awaits the task, then awaits the asynchronous callback only when the result is successful and its value is null.

public static Task<Result<TValue>> OnSuccessNullAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNullAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)

Awaits the value task, then awaits the asynchronous callback only when the result is successful and its value is null.

public static ValueTask<Result<TValue>> OnSuccessNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

func Func<Task>

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

func is null.

OnSuccessNull<TValue>(Result<TValue>, Action)

Invokes the callback only when the result is successful and its value is null.

public static Result<TValue> OnSuccessNull<TValue>(this Result<TValue> result, Action action)

Parameters

result Result<TValue>

The result to inspect.

action Action

The callback to run.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNull<TValue>(Task<Result<TValue>>, Action)

Awaits the task, then invokes the callback only when the result is successful and its value is null.

public static Task<Result<TValue>> OnSuccessNull<TValue>(this Task<Result<TValue>> result, Action action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccessNull<TValue>(ValueTask<Result<TValue>>, Action)

Awaits the value task, then invokes the callback only when the result is successful and its value is null.

public static ValueTask<Result<TValue>> OnSuccessNull<TValue>(this ValueTask<Result<TValue>> result, Action action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(Result<TValue>, Action)

Invokes the callback only when the result is successful.

public static Result<TValue> OnSuccess<TValue>(this Result<TValue> result, Action action)

Parameters

result Result<TValue>

The result to inspect.

action Action

The callback to run.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(Result<TValue>, Action<TValue>)

Invokes the callback with the value of the result only when the result is successful.

public static Result<TValue> OnSuccess<TValue>(this Result<TValue> result, Action<TValue> action)

Parameters

result Result<TValue>

The result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

Result<TValue>

The result received, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

A successful Result may still carry a null value: use OnSuccessNotNull<TValue>(Result<TValue>, Action<TValue>) when the callback needs a value it can dereference.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(Task<Result<TValue>>, Action)

Awaits the task, then invokes the callback only when the result is successful.

public static Task<Result<TValue>> OnSuccess<TValue>(this Task<Result<TValue>> result, Action action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action

The callback to run.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(Task<Result<TValue>>, Action<TValue>)

Awaits the task, then invokes the callback with the value of the result only when the result is successful.

public static Task<Result<TValue>> OnSuccess<TValue>(this Task<Result<TValue>> result, Action<TValue> action)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

Task<Result<TValue>>

A task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(ValueTask<Result<TValue>>, Action)

Awaits the value task, then invokes the callback only when the result is successful.

public static ValueTask<Result<TValue>> OnSuccess<TValue>(this ValueTask<Result<TValue>> result, Action action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action

The callback to run.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

OnSuccess<TValue>(ValueTask<Result<TValue>>, Action<TValue>)

Awaits the value task, then invokes the callback with the value of the result only when the result is successful.

public static ValueTask<Result<TValue>> OnSuccess<TValue>(this ValueTask<Result<TValue>> result, Action<TValue> action)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

action Action<TValue>

The callback receiving the value of the result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result, unchanged.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.

Exceptions

ArgumentNullException

action is null.

Recover(Result, Func<IReadOnlyCollection<IError>, Result>)

Replaces a failed result with the result of a fallback.

public static Result Recover(this Result result, Func<IReadOnlyCollection<IError>, Result> recovery)

Parameters

result Result

The result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result>

The fallback receiving the errors of the failed result.

Returns

Result

result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

A successful result is returned unchanged and recovery is not called. When the fallback succeeds, its result is returned and the original errors are dropped: the failure has been handled. When the fallback fails too, the new result carries the reasons of result followed by those of the fallback, so neither failure is lost. An exception thrown by the fallback propagates to the caller.

Exceptions

ArgumentNullException

recovery is null.

Recover(Task<Result>, Func<IReadOnlyCollection<IError>, Result>)

Awaits the task, then replaces a failed result with the result of a fallback.

public static Task<Result> Recover(this Task<Result> result, Func<IReadOnlyCollection<IError>, Result> recovery)

Parameters

result Task<Result>

The task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result>

The fallback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

Exceptions

ArgumentNullException

recovery is null.

Recover(ValueTask<Result>, Func<IReadOnlyCollection<IError>, Result>)

Awaits the value task, then replaces a failed result with the result of a fallback.

public static ValueTask<Result> Recover(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, Result> recovery)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result>

The fallback receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync(Result, Func<IReadOnlyCollection<IError>, Task<Result>>)

Awaits an asynchronous fallback replacing a failed result.

public static Task<Result> RecoverAsync(this Result result, Func<IReadOnlyCollection<IError>, Task<Result>> recovery)

Parameters

result Result

The result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result>>

The fallback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync(Task<Result>, Func<IReadOnlyCollection<IError>, Task<Result>>)

Awaits the task, then awaits an asynchronous fallback replacing a failed result.

public static Task<Result> RecoverAsync(this Task<Result> result, Func<IReadOnlyCollection<IError>, Task<Result>> recovery)

Parameters

result Task<Result>

The task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result>>

The fallback receiving the errors of the failed result.

Returns

Task<Result>

A task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync(ValueTask<Result>, Func<IReadOnlyCollection<IError>, Task<Result>>)

Awaits the value task, then awaits an asynchronous fallback replacing a failed result.

public static ValueTask<Result> RecoverAsync(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, Task<Result>> recovery)

Parameters

result ValueTask<Result>

The value task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result>>

The fallback receiving the errors of the failed result.

Returns

ValueTask<Result>

A value task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync<TValue>(Result<TValue>, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>)

Awaits an asynchronous fallback replacing a failed result.

public static Task<Result<TValue>> RecoverAsync<TValue>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>> recovery)

Parameters

result Result<TValue>

The result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>

The fallback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync<TValue>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>)

Awaits the task, then awaits an asynchronous fallback replacing a failed result.

public static Task<Result<TValue>> RecoverAsync<TValue>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>> recovery)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>

The fallback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

RecoverAsync<TValue>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>)

Awaits the value task, then awaits an asynchronous fallback replacing a failed result.

public static ValueTask<Result<TValue>> RecoverAsync<TValue>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task<Result<TValue>>> recovery)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Task<Result<TValue>>>

The fallback receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

Recover<TValue>(Result<TValue>, Func<IReadOnlyCollection<IError>, Result<TValue>>)

Replaces a failed result with the result of a fallback.

public static Result<TValue> Recover<TValue>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, Result<TValue>> recovery)

Parameters

result Result<TValue>

The result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result<TValue>>

The fallback receiving the errors of the failed result.

Returns

Result<TValue>

result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

Recover<TValue>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, Result<TValue>>)

Awaits the task, then replaces a failed result with the result of a fallback.

public static Task<Result<TValue>> Recover<TValue>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Result<TValue>> recovery)

Parameters

result Task<Result<TValue>>

The task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result<TValue>>

The fallback receiving the errors of the failed result.

Returns

Task<Result<TValue>>

A task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

Recover<TValue>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, Result<TValue>>)

Awaits the value task, then replaces a failed result with the result of a fallback.

public static ValueTask<Result<TValue>> Recover<TValue>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Result<TValue>> recovery)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to inspect.

recovery Func<IReadOnlyCollection<IError>, Result<TValue>>

The fallback receiving the errors of the failed result.

Returns

ValueTask<Result<TValue>>

A value task completing with the awaited result when it succeeded, the result of the fallback when it succeeded, or a new failed result with the reasons of both.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

recovery is null.

Then(Result, Func<Result>)

Runs the next step only when the result is successful, and continues with the result of that step.

public static Result Then(this Result result, Func<Result> next)

Parameters

result Result

The result to continue from.

next Func<Result>

The step.

Returns

Result

A new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

It is FluentResults' Bind under a name of the Arc4u chain, for every receiver. A failed result skips the step and its errors are carried on. Otherwise the new result carries the reasons of the original result followed by those of the step, and the value of the step. An exception thrown by the step propagates to the caller.

Exceptions

ArgumentNullException

next is null.

Then(Task<Result>, Func<Result>)

Awaits the task, then runs the next step only when the result is successful, and continues with the result of that step.

public static Task<Result> Then(this Task<Result> result, Func<Result> next)

Parameters

result Task<Result>

The task producing the result to continue from.

next Func<Result>

The step.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

Exceptions

ArgumentNullException

next is null.

Then(ValueTask<Result>, Func<Result>)

Awaits the value task, then runs the next step only when the result is successful, and continues with the result of that step.

public static ValueTask<Result> Then(this ValueTask<Result> result, Func<Result> next)

Parameters

result ValueTask<Result>

The value task producing the result to continue from.

next Func<Result>

The step.

Returns

ValueTask<Result>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync(Result, Func<Task<Result>>)

Awaits the next step only when the result is successful, and continues with the result of that step.

public static Task<Result> ThenAsync(this Result result, Func<Task<Result>> next)

Parameters

result Result

The result to continue from.

next Func<Task<Result>>

The step.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync(Task<Result>, Func<Task<Result>>)

Awaits the task, then awaits the next step only when the result is successful, and continues with the result of that step.

public static Task<Result> ThenAsync(this Task<Result> result, Func<Task<Result>> next)

Parameters

result Task<Result>

The task producing the result to continue from.

next Func<Task<Result>>

The step.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync(ValueTask<Result>, Func<Task<Result>>)

Awaits the value task, then awaits the next step only when the result is successful, and continues with the result of that step.

public static ValueTask<Result> ThenAsync(this ValueTask<Result> result, Func<Task<Result>> next)

Parameters

result ValueTask<Result>

The value task producing the result to continue from.

next Func<Task<Result>>

The step.

Returns

ValueTask<Result>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TNewValue>(Result, Func<Task<Result<TNewValue>>>)

Awaits the next step only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> ThenAsync<TNewValue>(this Result result, Func<Task<Result<TNewValue>>> next)

Parameters

result Result

The result to continue from.

next Func<Task<Result<TNewValue>>>

The step.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue>(Result<TValue>, Func<TValue, Task<Result>>)

Awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result> ThenAsync<TValue>(this Result<TValue> result, Func<TValue, Task<Result>> next)

Parameters

result Result<TValue>

The result to continue from.

next Func<TValue, Task<Result>>

The step receiving the value.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task<Result>>)

Awaits the task, then awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result> ThenAsync<TValue>(this Task<Result<TValue>> result, Func<TValue, Task<Result>> next)

Parameters

result Task<Result<TValue>>

The task producing the result to continue from.

next Func<TValue, Task<Result>>

The step receiving the value.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TNewValue>(Task<Result>, Func<Task<Result<TNewValue>>>)

Awaits the task, then awaits the next step only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> ThenAsync<TNewValue>(this Task<Result> result, Func<Task<Result<TNewValue>>> next)

Parameters

result Task<Result>

The task producing the result to continue from.

next Func<Task<Result<TNewValue>>>

The step.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Task<Result>>)

Awaits the value task, then awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static ValueTask<Result> ThenAsync<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task<Result>> next)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to continue from.

next Func<TValue, Task<Result>>

The step receiving the value.

Returns

ValueTask<Result>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TNewValue>(ValueTask<Result>, Func<Task<Result<TNewValue>>>)

Awaits the value task, then awaits the next step only when the result is successful, and continues with the result of that step.

public static ValueTask<Result<TNewValue>> ThenAsync<TNewValue>(this ValueTask<Result> result, Func<Task<Result<TNewValue>>> next)

Parameters

result ValueTask<Result>

The value task producing the result to continue from.

next Func<Task<Result<TNewValue>>>

The step.

Returns

ValueTask<Result<TNewValue>>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue, TNewValue>(Result<TValue>, Func<TValue, Task<Result<TNewValue>>>)

Awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> ThenAsync<TValue, TNewValue>(this Result<TValue> result, Func<TValue, Task<Result<TNewValue>>> next)

Parameters

result Result<TValue>

The result to continue from.

next Func<TValue, Task<Result<TNewValue>>>

The step receiving the value.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue, TNewValue>(Task<Result<TValue>>, Func<TValue, Task<Result<TNewValue>>>)

Awaits the task, then awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> ThenAsync<TValue, TNewValue>(this Task<Result<TValue>> result, Func<TValue, Task<Result<TNewValue>>> next)

Parameters

result Task<Result<TValue>>

The task producing the result to continue from.

next Func<TValue, Task<Result<TNewValue>>>

The step receiving the value.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

ThenAsync<TValue, TNewValue>(ValueTask<Result<TValue>>, Func<TValue, Task<Result<TNewValue>>>)

Awaits the value task, then awaits the next step with its value only when the result is successful, and continues with the result of that step.

public static ValueTask<Result<TNewValue>> ThenAsync<TValue, TNewValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task<Result<TNewValue>>> next)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to continue from.

next Func<TValue, Task<Result<TNewValue>>>

The step receiving the value.

Returns

ValueTask<Result<TNewValue>>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TNewValue>(Result, Func<Result<TNewValue>>)

Runs the next step only when the result is successful, and continues with the result of that step.

public static Result<TNewValue> Then<TNewValue>(this Result result, Func<Result<TNewValue>> next)

Parameters

result Result

The result to continue from.

next Func<Result<TNewValue>>

The step.

Returns

Result<TNewValue>

A new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue>(Result<TValue>, Func<TValue, Result>)

Runs the next step with its value only when the result is successful, and continues with the result of that step.

public static Result Then<TValue>(this Result<TValue> result, Func<TValue, Result> next)

Parameters

result Result<TValue>

The result to continue from.

next Func<TValue, Result>

The step receiving the value.

Returns

Result

A new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue>(Task<Result<TValue>>, Func<TValue, Result>)

Awaits the task, then runs the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result> Then<TValue>(this Task<Result<TValue>> result, Func<TValue, Result> next)

Parameters

result Task<Result<TValue>>

The task producing the result to continue from.

next Func<TValue, Result>

The step receiving the value.

Returns

Task<Result>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TNewValue>(Task<Result>, Func<Result<TNewValue>>)

Awaits the task, then runs the next step only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> Then<TNewValue>(this Task<Result> result, Func<Result<TNewValue>> next)

Parameters

result Task<Result>

The task producing the result to continue from.

next Func<Result<TNewValue>>

The step.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue>(ValueTask<Result<TValue>>, Func<TValue, Result>)

Awaits the value task, then runs the next step with its value only when the result is successful, and continues with the result of that step.

public static ValueTask<Result> Then<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Result> next)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to continue from.

next Func<TValue, Result>

The step receiving the value.

Returns

ValueTask<Result>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TNewValue>(ValueTask<Result>, Func<Result<TNewValue>>)

Awaits the value task, then runs the next step only when the result is successful, and continues with the result of that step.

public static ValueTask<Result<TNewValue>> Then<TNewValue>(this ValueTask<Result> result, Func<Result<TNewValue>> next)

Parameters

result ValueTask<Result>

The value task producing the result to continue from.

next Func<Result<TNewValue>>

The step.

Returns

ValueTask<Result<TNewValue>>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue, TNewValue>(Result<TValue>, Func<TValue, Result<TNewValue>>)

Runs the next step with its value only when the result is successful, and continues with the result of that step.

public static Result<TNewValue> Then<TValue, TNewValue>(this Result<TValue> result, Func<TValue, Result<TNewValue>> next)

Parameters

result Result<TValue>

The result to continue from.

next Func<TValue, Result<TNewValue>>

The step receiving the value.

Returns

Result<TNewValue>

A new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue, TNewValue>(Task<Result<TValue>>, Func<TValue, Result<TNewValue>>)

Awaits the task, then runs the next step with its value only when the result is successful, and continues with the result of that step.

public static Task<Result<TNewValue>> Then<TValue, TNewValue>(this Task<Result<TValue>> result, Func<TValue, Result<TNewValue>> next)

Parameters

result Task<Result<TValue>>

The task producing the result to continue from.

next Func<TValue, Result<TNewValue>>

The step receiving the value.

Returns

Task<Result<TNewValue>>

A task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.

Then<TValue, TNewValue>(ValueTask<Result<TValue>>, Func<TValue, Result<TNewValue>>)

Awaits the value task, then runs the next step with its value only when the result is successful, and continues with the result of that step.

public static ValueTask<Result<TNewValue>> Then<TValue, TNewValue>(this ValueTask<Result<TValue>> result, Func<TValue, Result<TNewValue>> next)

Parameters

result ValueTask<Result<TValue>>

The value task producing the result to continue from.

next Func<TValue, Result<TNewValue>>

The step receiving the value.

Returns

ValueTask<Result<TNewValue>>

A value task completing with a new result with the reasons of both and the value of the step, or with the errors of the original result.

Type Parameters

TValue

The type of the value carried by the result.

TNewValue

The type of the value produced by the step.

Remarks

Exceptions

ArgumentNullException

next is null.