OptTUnwrapOr(FuncT) Method

Returns the underlying value when IsSome; or returns lazyFallbackValue() when IsNone. This is a safe way to unwrap the optional, by explicitly handling the None variant. Use the eager UnwrapOr(T) variant if the fallback value is cheap or readily available.
C#
static int GetCapacity(IEnumerable<T> collection, Opt<int> givenCapacity) {
    // capacity will be either the givenCapacity, or the number of elements in the collection.
    // note that, collection.Count() might be expensive requiring linear search.
    // lazy call avoids this call when givenCapacity.IsSome.
    return givenCapacity.UnwrapOr(() => collection.Count());
}

Definition

Namespace: Orx.Fun.Option
Assembly: Orx.Fun.Option (in Orx.Fun.Option.dll) Version: 1.2.1+ea79806fa5e0e04bfdaef2a1916930e75e2cde74
C#
public T UnwrapOr(
	Func<T> lazyFallbackValue
)

Parameters

lazyFallbackValue  FuncT
Function to be called lazily to create the return value if the option is None.

Return Value

T

See Also