Table of Contents

Method ValueOr

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

ValueOr<T>(Maybe<T>, T)

Returns the contained value if there is one, and the given value otherwise.

[Pure]
public static T ValueOr<T>(this Maybe<T> a, T defaultValue)

Parameters

a Maybe<T>

The value to read.

defaultValue T

Returned when a contains no value.

Returns

T

The contained value, or defaultValue if there is none.

Type Parameters

T

The type of the value.

Remarks

This code evaluates defaultValue in each condition, because it is an argument. Where that is not wanted, use ValueOr<T>(Maybe<T>, Func<T>).

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

Returns the contained value if there is one, and the result of the given function otherwise.

[Pure]
public static T ValueOr<T>(this Maybe<T> a, Func<T> defaultValueFactory)

Parameters

a Maybe<T>

The value to read.

defaultValueFactory Func<T>

Run to give a value when a contains none.

Returns

T

The contained value, or the result of defaultValueFactory if there is none.

Type Parameters

T

The type of the value.

Remarks

defaultValueFactory is run only when there is no contained value.