Either<L, R>.fromPredicate constructor

Either<L, R>.fromPredicate(
  1. R r,
  2. bool predicate(
    1. R r
    ),
  3. L onFalse(
    1. R r
    )
)

If calling predicate with r returns true, then return Right(r). Otherwise return Left containing the result of onFalse.

Implementation

factory Either.fromPredicate(
  R r,
  bool Function(R r) predicate,
  L Function(R r) onFalse,
) =>
    predicate(r) ? Right(r) : Left(onFalse(r));