Show / Hide Table of Contents

Class OptionAsyncExtensions

Extension methods for async operations involving Option<T>.

Inheritance
object
OptionAsyncExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: RustyOptions.Async
Assembly: RustyOptions.dll
Syntax
public static class OptionAsyncExtensions

Methods

| Edit this page View Source

AndThenAsync<T1, T2>(Option<T1>, Func<T1, Task<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this Option<T1> self, Func<T1, Task<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The first option.

Func<T1, Task<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(Option<T1>, Func<T1, ValueTask<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this Option<T1> self, Func<T1, ValueTask<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The first option.

Func<T1, ValueTask<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(Task<Option<T1>>, Func<T1, Option<T2>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, Option<T2>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The first option.

Func<T1, Option<T2>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(Task<Option<T1>>, Func<T1, Task<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, Task<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The first option.

Func<T1, Task<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(Task<Option<T1>>, Func<T1, ValueTask<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, ValueTask<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The first option.

Func<T1, ValueTask<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, Option<T2>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, Option<T2>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The first option.

Func<T1, Option<T2>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, Task<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, Task<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The first option.

Func<T1, Task<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

AndThenAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, ValueTask<Option<T2>>>)

Asynchronously returns None if the option is None, otherwise calls thenFn with the wrapped value and returns the result.

Declaration
public static ValueTask<Option<T2>> AndThenAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, ValueTask<Option<T2>>> thenFn) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The first option.

Func<T1, ValueTask<Option<T2>>> thenFn

The function to call with the contained value, if there is a contained value.

Returns
Type Description
ValueTask<Option<T2>>
Type Parameters
Name Description
T1

The type contained by the first option.

T2

The type contained by the second option.

Exceptions
Type Condition
ArgumentNullException

Thrown if thenFn is null.

| Edit this page View Source

FirstOrNoneAsync<T>(IAsyncEnumerable<T>, Func<T, bool>, CancellationToken)

Returns the first element of a sequence, satisfying a specified predicate, if such exists.

Declaration
public static ValueTask<Option<T>> FirstOrNoneAsync<T>(this IAsyncEnumerable<T> self, Func<T, bool> predicate, CancellationToken ct = default) where T : notnull
Parameters
Type Name Description
IAsyncEnumerable<T> self

The sequence to return the first element from.

Func<T, bool> predicate

The predicate to filter by.

CancellationToken ct

A CancellationToken that will interrupt async iteration.

Returns
Type Description
ValueTask<Option<T>>

An Option<T> instance containing the first matching element, if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self or predicate is null.

| Edit this page View Source

FirstOrNoneAsync<T>(IAsyncEnumerable<T>, CancellationToken)

Returns the first element of an asynchronous sequence if such exists.

Declaration
public static ValueTask<Option<T>> FirstOrNoneAsync<T>(this IAsyncEnumerable<T> self, CancellationToken ct = default) where T : notnull
Parameters
Type Name Description
IAsyncEnumerable<T> self

The sequence to return the first element from.

CancellationToken ct

A CancellationToken that will interrupt async iteration.

Returns
Type Description
ValueTask<Option<T>>

An Option<T> instance containing the first element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

MapAsync<T1, T2>(Option<T1>, Func<T1, Task<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this Option<T1> self, Func<T1, Task<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(Option<T1>, Func<T1, ValueTask<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this Option<T1> self, Func<T1, ValueTask<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(Task<Option<T1>>, Func<T1, Task<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, Task<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(Task<Option<T1>>, Func<T1, ValueTask<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, ValueTask<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(Task<Option<T1>>, Func<T1, T2>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, T2> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, T2> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, Task<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, Task<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, ValueTask<T2>>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, ValueTask<T2>> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, T2>)

If the option has a value, passes that option to the mapper function and asynchronously returns that value as a Some.

Declaration
public static ValueTask<Option<T2>> MapAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, T2> mapper) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, T2> mapper

The function that maps the value contained in the option.

Returns
Type Description
ValueTask<Option<T2>>

The mapped value as Some, or None.

Type Parameters
Name Description
T1

The type of the option.

T2

The type returned by the mapper functions.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(Option<T1>, Func<T1, Task<T2>>, Func<Task<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this Option<T1> self, Func<T1, Task<T2>> mapper, Func<Task<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Func<Task<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(Option<T1>, Func<T1, ValueTask<T2>>, Func<ValueTask<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this Option<T1> self, Func<T1, ValueTask<T2>> mapper, Func<ValueTask<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Option<T1> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Func<ValueTask<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(Task<Option<T1>>, Func<T1, Task<T2>>, Func<Task<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, Task<T2>> mapper, Func<Task<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Func<Task<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(Task<Option<T1>>, Func<T1, ValueTask<T2>>, Func<ValueTask<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, ValueTask<T2>> mapper, Func<ValueTask<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Func<ValueTask<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(Task<Option<T1>>, Func<T1, T2>, Func<T2>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this Task<Option<T1>> self, Func<T1, T2> mapper, Func<T2> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
Task<Option<T1>> self

The option to map.

Func<T1, T2> mapper

The function that maps the value contained in the option.

Func<T2> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, Task<T2>>, Func<Task<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, Task<T2>> mapper, Func<Task<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, Task<T2>> mapper

The function that maps the value contained in the option.

Func<Task<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, ValueTask<T2>>, Func<ValueTask<T2>>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, ValueTask<T2>> mapper, Func<ValueTask<T2>> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, ValueTask<T2>> mapper

The function that maps the value contained in the option.

Func<ValueTask<T2>> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2>(ValueTask<Option<T1>>, Func<T1, T2>, Func<T2>)

Asynchronously computes a default function result (if None), or applies a different function to the contained value (if Some).

Declaration
public static ValueTask<T2> MapOrElseAsync<T1, T2>(this ValueTask<Option<T1>> self, Func<T1, T2> mapper, Func<T2> defaultFactory) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
ValueTask<Option<T1>> self

The option to map.

Func<T1, T2> mapper

The function that maps the value contained in the option.

Func<T2> defaultFactory

The function that lazily generates a default value, if required.

Returns
Type Description
ValueTask<T2>

The mapped value, or the default value.

Type Parameters
Name Description
T1

The type of the option's value.

T2

The return type after mapping.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

OrElseAsync<T>(Option<T>, Func<Task<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this Option<T> self, Func<Task<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
Option<T> self

The option.

Func<Task<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(Option<T>, Func<ValueTask<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this Option<T> self, Func<ValueTask<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
Option<T> self

The option.

Func<ValueTask<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(Task<Option<T>>, Func<Option<T>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this Task<Option<T>> self, Func<Option<T>> elseFn) where T : notnull
Parameters
Type Name Description
Task<Option<T>> self

The option.

Func<Option<T>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(Task<Option<T>>, Func<Task<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this Task<Option<T>> self, Func<Task<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
Task<Option<T>> self

The option.

Func<Task<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(Task<Option<T>>, Func<ValueTask<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this Task<Option<T>> self, Func<ValueTask<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
Task<Option<T>> self

The option.

Func<ValueTask<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(ValueTask<Option<T>>, Func<Option<T>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this ValueTask<Option<T>> self, Func<Option<T>> elseFn) where T : notnull
Parameters
Type Name Description
ValueTask<Option<T>> self

The option.

Func<Option<T>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(ValueTask<Option<T>>, Func<Task<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this ValueTask<Option<T>> self, Func<Task<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
ValueTask<Option<T>> self

The option.

Func<Task<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

OrElseAsync<T>(ValueTask<Option<T>>, Func<ValueTask<Option<T>>>)

Asynchronously returns self if it contains a value, otherwise calls elseFn and returns the result.

Declaration
public static ValueTask<Option<T>> OrElseAsync<T>(this ValueTask<Option<T>> self, Func<ValueTask<Option<T>>> elseFn) where T : notnull
Parameters
Type Name Description
ValueTask<Option<T>> self

The option.

Func<ValueTask<Option<T>>> elseFn

The function that creates the alternate value if the option is None.

Returns
Type Description
ValueTask<Option<T>>
Type Parameters
Name Description
T

The type contained by the option.

Exceptions
Type Condition
ArgumentNullException

Thrown if elseFn is null.

| Edit this page View Source

ValuesAsync<T>(IAsyncEnumerable<Option<T>>, CancellationToken)

Flattens an asynchronous sequence of Option<T> into a sequence containing all inner values. Empty elements are discarded.

Declaration
public static IAsyncEnumerable<T> ValuesAsync<T>(this IAsyncEnumerable<Option<T>> self, CancellationToken ct = default) where T : notnull
Parameters
Type Name Description
IAsyncEnumerable<Option<T>> self

The sequence of options.

CancellationToken ct

A CancellationToken that will interrupt async iteration.

Returns
Type Description
IAsyncEnumerable<T>

A flattened sequence of values.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX