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
aMaybe<T>The value to read.
defaultValueTReturned when
acontains no value.
Returns
- T
The contained value, or
defaultValueif there is none.
Type Parameters
TThe 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
Returns
- T
The contained value, or the result of
defaultValueFactoryif there is none.
Type Parameters
TThe type of the value.
Remarks
defaultValueFactory is run only when there is no
contained value.