/** * If the condition satisfies, return the given A in left, otherwise, return the given B in right. * * @param c The condition to test. * @param right The right value to use if the condition satisfies. * @param left The left value to use if the condition does not satisfy. * @return A constructed either based on the given condition. */ public static <A, B> Either<A, B> iif(final boolean c, final P1<B> right, final P1<A> left) { return c ? new Right<A, B>(right._1()) : new Left<A, B>(left._1()); }
/** * The value of this projection or the given argument. * * @param b The value to return if this projection has no value. * @return The value of this projection or the given argument. */ public B orValue(final P1<B> b) { return isRight() ? value() : b._1(); }
/** * The value of this projection or the given argument. * * @param a The value to return if this projection has no value. * @return The value of this projection or the given argument. */ public A orValue(final P1<A> a) { return isLeft() ? value() : a._1(); }
/** * Returns the value of this projection or fails with the given error message. * * @param err The error message to fail with. * @return The value of this projection */ public B valueE(final P1<String> err) { if (e.isRight()) //noinspection CastToConcreteClass return ((Right<A, B>) e).b; else throw error(err._1()); }
/** * Returns the value of this projection or fails with the given error message. * * @param err The error message to fail with. * @return The value of this projection */ public A valueE(final P1<String> err) { if (e.isLeft()) //noinspection CastToConcreteClass return ((Left<A, B>) e).a; else throw error(err._1()); }