public <X> Either<A, B> fold(Action<A> fa, Action<B> fb) { if (isLeft()) { fa.apply(left.get()); return new Either<A, B>(left.get(), null); } else if (isRight()) { fb.apply(right.get()); return new Either<A, B>(null, right.get()); } else { return new Either<A, B>(null, null); } }
public <X> Option<X> fold(Function<A, X> fa, Function<B, X> fb) { if (isLeft()) { return Option.maybe(fa.apply(left.get())); } else if (isRight()) { return Option.maybe(fb.apply(right.get())); } else { return (Option<X>) Option.none(); } }
public Either<B, A> swap() { A vLeft = null; B vRight = null; if (left.isDefined()) { vLeft = left.get(); } if (right.isDefined()) { vRight = right.get(); } return new Either<B, A>(vRight, vLeft); }