Optional<T>.ofNullable constructor

Optional<T>.ofNullable(
  1. T? value
)

Creates a new Optional with the given value, if non-null. Otherwise, returns an empty Optional.

Implementation

factory Optional.ofNullable(T? value) {
  if (value == null) {
    return empty.cast();
  } else {
    return _Present<T>(value);
  }
}