The first Optional
if Some
, otherwise the alternative.
const preferred = Optional.some('primary');
const fallback = Optional.some('secondary');
const noneValue = Optional.none as Optional<string>;
assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);
const orElseFallback = Optional.orElse(Optional.some('default'));
assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default'));
assert.deepStrictEqual(
orElseFallback(Optional.some('value')),
Optional.some('value'),
);
Returns the Optional
if it is Some
, otherwise returns the alternative.
Provides a way to chain Optional operations with fallback values. This is particularly useful for implementing default behavior or cascading lookups. Supports both direct usage and curried form for functional composition.
The first Optional
if Some
, otherwise the alternative.
const preferred = Optional.some('primary');
const fallback = Optional.some('secondary');
const noneValue = Optional.none as Optional<string>;
assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);
const orElseFallback = Optional.orElse(Optional.some('default'));
assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default'));
assert.deepStrictEqual(
orElseFallback(Optional.some('value')),
Optional.some('value'),
);
Returns the
Optional
if it isSome
, otherwise returns the alternative.Provides a way to chain Optional operations with fallback values. This is particularly useful for implementing default behavior or cascading lookups. Supports both direct usage and curried form for functional composition.