OptTUnwrapOrAsync Method
(async version)
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.
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());
}
Namespace: Orx.Fun.OptionAssembly: Orx.Fun.Option (in Orx.Fun.Option.dll) Version: 1.2.1+ea79806fa5e0e04bfdaef2a1916930e75e2cde74
public Task<T> UnwrapOrAsync(
Func<Task<T>> lazyFallbackValue
)
- lazyFallbackValue FuncTaskT
- Function to be called lazily to create the return value if the option is None.
TaskT