The UnknownOptional type to unwrap.
The type of the default value.
The contained value if Some, otherwise defaultValue.
const withValue = Optional.some(5);
const withoutValue = Optional.none as Optional<number>;
assert.isTrue(Optional.unwrapOr(withValue, 0) === 5);
assert.isTrue(Optional.unwrapOr(withoutValue, 0) === 0);
const unwrapWithDefault = Optional.unwrapOr(10);
assert.isTrue(unwrapWithDefault(Optional.some(3)) === 3);
assert.isTrue(unwrapWithDefault(Optional.none) === 10);
Unwraps an Optional, returning the contained value or a default value if
it's None.
Supports both direct usage and curried form for functional composition.
This is often preferred over unwrap() when you have a sensible fallback
value.
The type of the default value.
The value to return if optional is None.
The contained value if Some, otherwise defaultValue.
const withValue = Optional.some(5);
const withoutValue = Optional.none as Optional<number>;
assert.isTrue(Optional.unwrapOr(withValue, 0) === 5);
assert.isTrue(Optional.unwrapOr(withoutValue, 0) === 0);
const unwrapWithDefault = Optional.unwrapOr(10);
assert.isTrue(unwrapWithDefault(Optional.some(3)) === 3);
assert.isTrue(unwrapWithDefault(Optional.none) === 10);
Unwraps an
Optional, returning the contained value or a default value if it'sNone.Supports both direct usage and curried form for functional composition. This is often preferred over
unwrap()when you have a sensible fallback value.