Result<L, R>.fromNullable constructor
Result<L, R>.fromNullable (
- R? value,
- L onNull()
Creates a Success from a non-null value, or Failure from onNull if null.
Useful for bridging nullable APIs into the Result world.
final result = Result<String, int>.fromNullable(
json['age'] as int?,
() => 'age field is missing',
); // Success(25) or Failure('age field is missing')
Implementation
factory Result.fromNullable(R? value, L Function() onNull) =>
value != null ? Success<L, R>(value) : Failure<L, R>(onNull());