filter<L, R> function
Either<L, R> Function(Either<L, R> either)
filter<L, R>(
- bool predicate(
- R right
- L orElse(
- R right
Maybe converts an Either to a Left, determined by the given predicate
.
final greaterThanFiveFilter = filter(
(int i) => i > 5,
(i) => '$i is too small',
);
expect(
right(10).chain(greaterThanFiveFilter),
right(10),
);
expect(
right(3).chain(greaterThanFiveFilter),
left('3 is too small'),
);
Implementation
Either<L, R> Function(Either<L, R> either) filter<L, R>(
bool Function(R right) predicate,
L Function(R right) orElse,
) =>
flatMap(fromPredicateK(predicate, orElse));