Table of Contents

Method OrElse

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

OrElse<T>(Maybe<T>, Maybe<T>)

Returns this value if it has one, and the given value otherwise.

[Pure]
public static Maybe<T> OrElse<T>(this Maybe<T> a, Maybe<T> b)

Parameters

a Maybe<T>

The value to prefer.

b Maybe<T>

Returned when a contains no value.

Returns

Maybe<T>

a if it contains a value, and b otherwise.

Type Parameters

T

The type of the value.

Remarks

In a chain, this is a list of fallbacks. The first source with an answer wins, and the result has no value only when no source had one.

OrElse<T>(Maybe<T>, Func<Maybe<T>>)

Returns this value if it has one, and the result of the given function otherwise.

[Pure]
public static Maybe<T> OrElse<T>(this Maybe<T> a, Func<Maybe<T>> b)

Parameters

a Maybe<T>

The value to prefer.

b Func<Maybe<T>>

Run to give a fallback when a contains no value.

Returns

Maybe<T>

a if it contains a value, and the result of b otherwise.

Type Parameters

T

The type of the value.

Remarks

b runs only when a has no value. Thus, use this version when a read of the fallback costs something, such as a second lookup or a second parse.