/** * Apply the specified predicate to `A` and construct `E` in case that the * specified predicate returns `false`. * * @tsplus static Either.Aspects filterOrElse * @tsplus pipeable Either filterOrElse */ export function filterOrElse( f: Refinement, onFalse: (a: A) => E ): (self: Either) => Either export function filterOrElse( f: Predicate, onFalse: (a: A) => E ): (self: Either) => Either export function filterOrElse(f: Predicate, onFalse: (a: A) => E) { return (self: Either): Either => self.flatMap( (a) => (f(a) ? Either.right(a) : Either.left(onFalse(a))) ) }