fromOption<L, R> function
Converts an Option into an Either.
If the Option is Some, then a Right is returned with the wrapped
value.
Otherwise, onNone
will determine the Left value to return.
expect(
O.some('hello').chain(fromOption(() => 'fail')),
right('hello'),
);
expect(
O.none().chain(fromOption(() => 'fail')),
left('fail'),
);
Implementation
Either<L, R> Function(Option<R> option) fromOption<L, R>(
L Function() onNone,
) =>
O.fold(() => left(onNone()), right);