toNullable method

T? toNullable()

Returns the present value, or null when absent.

This collapses None() and Some<T?>(null) into the same null, which is exactly the distinction Option exists to keep. Use it at the edge where code wants a plain nullable value back.

final value = const Some<int>(1).toNullable(); // 1
final missing = const None<int>().toNullable(); // null

Implementation

T? toNullable() {
  return switch (this) {
    Some<T>(:final value) => value,
    None<T>() => null,
  };
}