Show / Hide Table of Contents

Class ResultAsyncExtensions

Extension methods for async operations involving Result<T, TErr>.

Inheritance
object
ResultAsyncExtensions
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 ResultAsyncExtensions

Methods

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, Task<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, Task<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, ValueTask<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, ValueTask<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, Result<T2, TErr>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, Result<T2, TErr>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, Task<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, Task<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, ValueTask<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, ValueTask<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, Result<T2, TErr>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, Result<T2, TErr>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, Task<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, Task<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

AndThenAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, ValueTask<Result<T2, TErr>>>)

Asynchronously calls thenFunc if the result is Ok, otherwise returns the Err value of self.

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

The result.

Func<T1, ValueTask<Result<T2, TErr>>> thenFunc

The function to call with the Ok value, if any.

Returns
Type Description
ValueTask<Result<T2, TErr>>

The result of calling thenFunc if the result is Ok, otherwise the Err value of self.

Type Parameters
Name Description
T1

The Ok type of self.

T2

The Ok type returned by thenFunc.

TErr

The Err type.

| Edit this page View Source

ErrorsAsync<T, TErr>(IAsyncEnumerable<Result<T, TErr>>, CancellationToken)

Flattens an asynchronous sequence of Result<T, TErr> into a sequence containing all error values. Ok results are discarded.

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

The asynchronsou sequence of results.

CancellationToken ct

A CancellationToken that will interrupt async iteration.

Returns
Type Description
IAsyncEnumerable<TErr>

A flattened sequence of values.

Type Parameters
Name Description
T
TErr
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, Task<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, ValueTask<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, Task<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, ValueTask<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, T2>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, T2> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, Task<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, ValueTask<T2>>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, T2>)

Asynchronously maps a result by applying a function to a contained Ok value, leaving an Err value untouched.

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

The result to map.

Func<T1, T2> mapper

The function that converts a contained Ok value to T2.

Returns
Type Description
ValueTask<Result<T2, TErr>>

A result containing the mapped value, or Err.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, Task<T2>>, Func<TErr, Task<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, Task<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(Result<T1, TErr>, Func<T1, ValueTask<T2>>, Func<TErr, ValueTask<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, ValueTask<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, Task<T2>>, Func<TErr, Task<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, Task<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, ValueTask<T2>>, Func<TErr, ValueTask<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, ValueTask<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(Task<Result<T1, TErr>>, Func<T1, T2>, Func<TErr, T2>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, T2> mapper

The function that converts a contained Ok value to T2.

Func<TErr, T2> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, Task<T2>>, Func<TErr, Task<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, Task<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, Task<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, ValueTask<T2>>, Func<TErr, ValueTask<T2>>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, ValueTask<T2>> mapper

The function that converts a contained Ok value to T2.

Func<TErr, ValueTask<T2>> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

MapOrElseAsync<T1, T2, TErr>(ValueTask<Result<T1, TErr>>, Func<T1, T2>, Func<TErr, T2>)

Asynchronously maps a Result by applying fallback function defaultFactory to a contained Err value, or function mapper to a contained Ok value.

This function can be used to unpack a successful result while handling an error.

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

The result to map.

Func<T1, T2> mapper

The function that converts a contained Ok value to T2.

Func<TErr, T2> defaultFactory

The function that converts a contained Err value to T2.

Returns
Type Description
ValueTask<T2>

The mapped value.

Type Parameters
Name Description
T1

The Ok type contained by self.

T2

The Ok type contained by the return value.

TErr

The Err type.

Exceptions
Type Condition
ArgumentNullException

Thrown if mapper or defaultFactory is null.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(Result<T, T1Err>, Func<T1Err?, Task<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this Result<T, T1Err> self, Func<T1Err?, Task<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
Result<T, T1Err> self

The result.

Func<T1Err, Task<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(Result<T, T1Err>, Func<T1Err?, ValueTask<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this Result<T, T1Err> self, Func<T1Err?, ValueTask<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
Result<T, T1Err> self

The result.

Func<T1Err, ValueTask<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(Task<Result<T, T1Err>>, Func<T1Err?, Result<T, T2Err>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this Task<Result<T, T1Err>> self, Func<T1Err?, Result<T, T2Err>> elseFunc) where T : notnull
Parameters
Type Name Description
Task<Result<T, T1Err>> self

The result.

Func<T1Err, Result<T, T2Err>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(Task<Result<T, T1Err>>, Func<T1Err?, Task<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this Task<Result<T, T1Err>> self, Func<T1Err?, Task<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
Task<Result<T, T1Err>> self

The result.

Func<T1Err, Task<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(Task<Result<T, T1Err>>, Func<T1Err?, ValueTask<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this Task<Result<T, T1Err>> self, Func<T1Err?, ValueTask<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
Task<Result<T, T1Err>> self

The result.

Func<T1Err, ValueTask<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(ValueTask<Result<T, T1Err>>, Func<T1Err?, Result<T, T2Err>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this ValueTask<Result<T, T1Err>> self, Func<T1Err?, Result<T, T2Err>> elseFunc) where T : notnull
Parameters
Type Name Description
ValueTask<Result<T, T1Err>> self

The result.

Func<T1Err, Result<T, T2Err>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(ValueTask<Result<T, T1Err>>, Func<T1Err?, Task<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this ValueTask<Result<T, T1Err>> self, Func<T1Err?, Task<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
ValueTask<Result<T, T1Err>> self

The result.

Func<T1Err, Task<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

OrElseAsync<T, T1Err, T2Err>(ValueTask<Result<T, T1Err>>, Func<T1Err?, ValueTask<Result<T, T2Err>>>)

Asynchronously calls elseFunc if the result is Err, otherwise returns the Ok value of self.

Declaration
public static ValueTask<Result<T, T2Err>> OrElseAsync<T, T1Err, T2Err>(this ValueTask<Result<T, T1Err>> self, Func<T1Err?, ValueTask<Result<T, T2Err>>> elseFunc) where T : notnull
Parameters
Type Name Description
ValueTask<Result<T, T1Err>> self

The result.

Func<T1Err, ValueTask<Result<T, T2Err>>> elseFunc

The function to call with the Err value, if any.

Returns
Type Description
ValueTask<Result<T, T2Err>>

The Ok value of the result, or the result of passing the Err value to elseFunc.

Type Parameters
Name Description
T

The Ok type of the result.

T1Err

The Err type of self.

T2Err

The Err type returned by elseFunc.

| Edit this page View Source

ValuesAsync<T, TErr>(IAsyncEnumerable<Result<T, TErr>>, CancellationToken)

Flattens an asynchronous sequence of Result<T, TErr> into a sequence containing all inner values. Error results are discarded.

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

The asynchronsous sequence of results.

CancellationToken ct

A CancellationToken that will interrupt async iteration.

Returns
Type Description
IAsyncEnumerable<T>

A flattened sequence of values.

Type Parameters
Name Description
T
TErr
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

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