filter method

Either<L, R> filter(
  1. bool predicate(
    1. R
    ),
  2. L orElse()
)

Filters the right value with a predicate, converting to Left if false

Implementation

Either<L, R> filter(bool Function(R) predicate, L Function() orElse) {
  return switch (this) {
    Left() => this,
    Right(:final value) => predicate(value) ? this : Left(orElse()),
  };
}