Option<T>.fromNullable constructor
Option<T>.fromNullable (
- T? value
Wraps a nullable value: null becomes None, anything else Some.
This is the one place a Dart null turns into absence. Build a
Some<T?>(null) directly when null is a present value you want to
keep, such as a field explicitly cleared rather than left out.
final missing = Option<String>.fromNullable(null); // None()
final present = Option<String>.fromNullable('John'); // Some(John)
Implementation
factory Option.fromNullable(T? value) {
return value == null ? None<T>() : Some<T>(value);
}