unwrapOption
Call Signature
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 tonull.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of the contained value. |
Parameters
Returns
T | null
The contained value if Some, otherwise the fallback value.
Examples
Unwrapping an Option with no fallback.
Providing a custom fallback value.
See
Call Signature
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 tonull.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of the contained value. |
U | The type of the fallback value (defaults to null). |
Parameters
| Parameter | Type | Description |
|---|---|---|
option | Option<T> | The Option to unwrap. |
fallback | () => U | A 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.
Providing a custom fallback value.