fromNullable<A> function
- A? value
Returns an Option from a nullable value.
This function takes in a nullable value of type A?
.
If the given value is non-null, this function will return Some containing the value. If the value is null, it will return None.
Example usage:
final someOption = fromNullable(42); // This will be Some(42)
final noneOption = fromNullable<int>(null); // This will be None
fromNullable can be useful for dealing with nullable values in a type-safe way. Rather than dealing with nullability throughout your code, you can encapsulate nullability in an Option and work with that instead.
Implementation
Option<A> fromNullable<A>(A? value) {
return value != null ? Some(value) : None();
}