Table of Contents

Method MapAsync

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

MapAsync<T, TResult>(Maybe<T>, Func<T, Task<TResult>>)

Transforms the contained value with an asynchronous function, if there is one.

public static Task<Maybe<TResult>> MapAsync<T, TResult>(this Maybe<T> a, Func<T, Task<TResult>> f)

Parameters

a Maybe<T>

The value to transform.

f Func<T, Task<TResult>>

Run with the contained value when there is one.

Returns

Task<Maybe<TResult>>

A task giving a Maybe<T> containing the result of f if a contained a value, and one containing no value otherwise.

Type Parameters

T

The type of the value, when there is one.

TResult

The type of the value the function produces.

Remarks

f is not run when there is no value, thus this is also how to prevent starting work that has no input.

MapAsync<T, TResult>(Task<Maybe<T>>, Func<T, Task<TResult>>)

Transforms the value the task will give with an asynchronous function, if it gives one.

public static Task<Maybe<TResult>> MapAsync<T, TResult>(this Task<Maybe<T>> a, Func<T, Task<TResult>> f)

Parameters

a Task<Maybe<T>>

The task giving the value to transform.

f Func<T, Task<TResult>>

Run with the contained value when there is one.

Returns

Task<Maybe<TResult>>

A task giving a Maybe<T> containing the result of f if the awaited value contained one, and one containing no value otherwise.

Type Parameters

T

The type of the value, when there is one.

TResult

The type of the value the function produces.