unwrapOption<T> function

T? unwrapOption<T>(
  1. Option<T> option
)

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

  • If the option is Some, returns the contained value T.
  • If the option is None, returns null.
unwrapOption(some(42)); // 42
unwrapOption(none<int>()); // null

Implementation

T? unwrapOption<T>(Option<T> option) {
  return switch (option) {
    Some<T>(:final value) => value,
    None<T>() => null,
  };
}