Table of Contents

Class MaybeExtensionsAsync

Namespace
Trellis
Assembly
Trellis.Core.dll

Asynchronous MatchAsync extension methods for Task<TResult> and ValueTask<TResult> of Maybe<T>.

public static class MaybeExtensionsAsync
Inheritance
MaybeExtensionsAsync
Inherited Members

Remarks

Mirrors the synchronous Match<TResult>(Func<T, TResult>, Func<TResult>) pattern, awaiting the upstream maybe carrier and dispatching to either the some or none branch. Both sync and async branch overloads are provided.

Methods

MatchAsync<TValue, TResult>(Task<Maybe<TValue>>, Func<TValue, Task<TResult>>, Func<Task<TResult>>)

Asynchronously pattern-matches on a Maybe<T> produced by a Task<TResult>, awaiting the asynchronous some branch when a value is present or the asynchronous none branch otherwise.

public static Task<TResult> MatchAsync<TValue, TResult>(this Task<Maybe<TValue>> maybeTask, Func<TValue, Task<TResult>> some, Func<Task<TResult>> none) where TValue : notnull

Parameters

maybeTask Task<Maybe<TValue>>

The task containing the Maybe instance to match on.

some Func<TValue, Task<TResult>>

The asynchronous function to invoke when the Maybe has a value.

none Func<Task<TResult>>

The asynchronous function to invoke when the Maybe has no value.

Returns

Task<TResult>

A task containing the result of the awaited branch.

Type Parameters

TValue

Type of the value contained in the Maybe.

TResult

The return type of the match.

Exceptions

ArgumentNullException

Thrown when some or none is null.

MatchAsync<TValue, TResult>(Task<Maybe<TValue>>, Func<TValue, TResult>, Func<TResult>)

Asynchronously pattern-matches on a Maybe<T> produced by a Task<TResult>, invoking the synchronous some branch when a value is present or the synchronous none branch otherwise.

public static Task<TResult> MatchAsync<TValue, TResult>(this Task<Maybe<TValue>> maybeTask, Func<TValue, TResult> some, Func<TResult> none) where TValue : notnull

Parameters

maybeTask Task<Maybe<TValue>>

The task containing the Maybe instance to match on.

some Func<TValue, TResult>

The function to invoke when the Maybe has a value.

none Func<TResult>

The function to invoke when the Maybe has no value.

Returns

Task<TResult>

A task containing the result of the matched branch.

Type Parameters

TValue

Type of the value contained in the Maybe.

TResult

The return type of the match.

Exceptions

ArgumentNullException

Thrown when some or none is null.

MatchAsync<TValue, TResult>(ValueTask<Maybe<TValue>>, Func<TValue, ValueTask<TResult>>, Func<ValueTask<TResult>>)

Asynchronously pattern-matches on a Maybe<T> produced by a ValueTask<TResult>, awaiting the asynchronous some branch when a value is present or the asynchronous none branch otherwise.

public static ValueTask<TResult> MatchAsync<TValue, TResult>(this ValueTask<Maybe<TValue>> maybeTask, Func<TValue, ValueTask<TResult>> some, Func<ValueTask<TResult>> none) where TValue : notnull

Parameters

maybeTask ValueTask<Maybe<TValue>>

The ValueTask containing the Maybe instance to match on.

some Func<TValue, ValueTask<TResult>>

The asynchronous function to invoke when the Maybe has a value.

none Func<ValueTask<TResult>>

The asynchronous function to invoke when the Maybe has no value.

Returns

ValueTask<TResult>

A ValueTask containing the result of the awaited branch.

Type Parameters

TValue

Type of the value contained in the Maybe.

TResult

The return type of the match.

Exceptions

ArgumentNullException

Thrown when some or none is null.

MatchAsync<TValue, TResult>(ValueTask<Maybe<TValue>>, Func<TValue, TResult>, Func<TResult>)

Asynchronously pattern-matches on a Maybe<T> produced by a ValueTask<TResult>, invoking the synchronous some branch when a value is present or the synchronous none branch otherwise.

public static ValueTask<TResult> MatchAsync<TValue, TResult>(this ValueTask<Maybe<TValue>> maybeTask, Func<TValue, TResult> some, Func<TResult> none) where TValue : notnull

Parameters

maybeTask ValueTask<Maybe<TValue>>

The ValueTask containing the Maybe instance to match on.

some Func<TValue, TResult>

The function to invoke when the Maybe has a value.

none Func<TResult>

The function to invoke when the Maybe has no value.

Returns

ValueTask<TResult>

A ValueTask containing the result of the matched branch.

Type Parameters

TValue

Type of the value contained in the Maybe.

TResult

The return type of the match.

Exceptions

ArgumentNullException

Thrown when some or none is null.

ToResultAsync<TValue>(Task<Maybe<TValue>>, Func<Error>)

Asynchronously converts a Maybe<T> to a Result<TValue> using a function to create the error. If the Maybe has a value, returns success; otherwise, returns failure with an error from the function.

public static Task<Result<TValue>> ToResultAsync<TValue>(this Task<Maybe<TValue>> maybeTask, Func<Error> ferror) where TValue : notnull

Parameters

maybeTask Task<Maybe<TValue>>

The task containing the Maybe instance to convert.

ferror Func<Error>

A function that produces the error if the Maybe has no value.

Returns

Task<Result<TValue>>

A task containing a Result with the Maybe's value or an error from the function.

Type Parameters

TValue

Type of the value contained in Maybe.

ToResultAsync<TValue>(Task<Maybe<TValue>>, Error)

Asynchronously converts a Maybe<T> to a Result<TValue>. If the Maybe has a value, returns success; otherwise, returns failure with the specified error.

public static Task<Result<TValue>> ToResultAsync<TValue>(this Task<Maybe<TValue>> maybeTask, Error error) where TValue : notnull

Parameters

maybeTask Task<Maybe<TValue>>

The task containing the Maybe instance to convert.

error Error

The error to return if the Maybe has no value.

Returns

Task<Result<TValue>>

A task containing a Result with the Maybe's value or the specified error.

Type Parameters

TValue

Type of the value contained in Maybe.

ToResultAsync<TValue>(ValueTask<Maybe<TValue>>, Func<Error>)

Asynchronously converts a Maybe<T> to a Result<TValue> using a ValueTask and a function to create the error. If the Maybe has a value, returns success; otherwise, returns failure with an error from the function.

public static ValueTask<Result<TValue>> ToResultAsync<TValue>(this ValueTask<Maybe<TValue>> maybeTask, Func<Error> ferror) where TValue : notnull

Parameters

maybeTask ValueTask<Maybe<TValue>>

The ValueTask containing the Maybe instance to convert.

ferror Func<Error>

A function that produces the error if the Maybe has no value.

Returns

ValueTask<Result<TValue>>

A ValueTask containing a Result with the Maybe's value or an error from the function.

Type Parameters

TValue

Type of the value contained in Maybe.

ToResultAsync<TValue>(ValueTask<Maybe<TValue>>, Error)

Asynchronously converts a Maybe<T> to a Result<TValue> using a ValueTask. If the Maybe has a value, returns success; otherwise, returns failure with the specified error.

public static ValueTask<Result<TValue>> ToResultAsync<TValue>(this ValueTask<Maybe<TValue>> maybeTask, Error error) where TValue : notnull

Parameters

maybeTask ValueTask<Maybe<TValue>>

The ValueTask containing the Maybe instance to convert.

error Error

The error to return if the Maybe has no value.

Returns

ValueTask<Result<TValue>>

A ValueTask containing a Result with the Maybe's value or the specified error.

Type Parameters

TValue

Type of the value contained in Maybe.