Either<L, R>.fromOption constructor

Either<L, R>.fromOption(
  1. Option<R> m,
  2. L onNone()
)

Return an Either from a Option:

  • If Option is Some, then return Right containing its value
  • If Option is None, then return Left containing the result of onNone

Implementation

factory Either.fromOption(Option<R> m, L Function() onNone) => m.match(
      () => Either.left(onNone()),
      (r) => Either.of(r),
    );