fromPredicateK<L, R> function

Either<L, R> Function(R value) fromPredicateK<L, R>(
  1. bool predicate(
    1. R value
    ),
  2. L orElse(
    1. R value
    )
)

Wrapper for fromPredicate, that returns a function which transforms a value into an Either.

final transform = fromPredicateK(
  (int number) => number > 1,
  (_) => 'number too small',
);

expect(transform(2), right(2));
expect(transform(0), left('number too small'));

Implementation

Either<L, R> Function(R value) fromPredicateK<L, R>(
  bool Function(R value) predicate,
  L Function(R value) orElse,
) =>
    (r) => fromPredicate(r, predicate, orElse);