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.

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

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.

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.