fromNullable<L, R> function
Create an Either from a nullable value.
If the value is null
, then the result of the orElse
function is used
as a Left value.
expect(
fromNullable('hello', () => 'it was null'),
right('hello'),
);
expect(
fromNullable(null, () => 'it was null'),
left('it was null'),
);
Implementation
Either<L, R> fromNullable<L, R>(
R? value,
Lazy<L> orElse,
) =>
value != null ? right(value) : left(orElse());