Kit
Functions

unwrapOption

Call Signature

unwrapOption<T>(option): null | T

Unwraps the value of an Option, returning its contained value or a fallback.

This function extracts the value T from an Option<T> type.

  • If the option is Some, it returns the contained value T.
  • If the option is None, it returns the fallback value U, which defaults to null.

Type Parameters

Type ParameterDescription
TThe type of the contained value.

Parameters

ParameterTypeDescription
optionOption<T>The Option to unwrap.

Returns

null | T

The contained value if Some, otherwise the fallback value.

Examples

Unwrapping an Option with no fallback.

unwrapOption(some('Hello World')); // "Hello World"
unwrapOption(none());              // null

Providing a custom fallback value.

unwrapOption(some('Hello World'), () => 'Default'); // "Hello World"
unwrapOption(none(), () => 'Default');              // "Default"

See

Call Signature

unwrapOption<T, U>(option, fallback): T | U

Unwraps the value of an Option, returning its contained value or a fallback.

This function extracts the value T from an Option<T> type.

  • If the option is Some, it returns the contained value T.
  • If the option is None, it returns the fallback value U, which defaults to null.

Type Parameters

Type ParameterDescription
TThe type of the contained value.
UThe type of the fallback value (defaults to null).

Parameters

ParameterTypeDescription
optionOption<T>The Option to unwrap.
fallback() => UA function that provides a fallback value if the option is None.

Returns

T | U

The contained value if Some, otherwise the fallback value.

Examples

Unwrapping an Option with no fallback.

unwrapOption(some('Hello World')); // "Hello World"
unwrapOption(none());              // null

Providing a custom fallback value.

unwrapOption(some('Hello World'), () => 'Default'); // "Hello World"
unwrapOption(none(), () => 'Default');              // "Default"

See

On this page