@Test public void testFold() { Either<String, Integer> a = left("a"); assertEquals("a", a.fold(new Either.Match<String, Integer, String>() { @Override public String left(String s) { return s; } @Override public String right(Integer integer) { return integer.toString(); } })); Either<String, Integer> b = right(1); assertEquals("1", b.fold(new Either.Match<String, Integer, String>() { @Override public String left(String s) { return s; } @Override public String right(Integer integer) { return integer.toString(); } })); }
public abstract <X> X fold(Match<A, B, X> visitor);
Either { public abstract <X> X fold(Match<A, B, X> visitor); }
Either { public abstract <X> X fold(Match<A, B, X> visitor); private  Either(); }
Either { public abstract <X> X fold(Match<A, B, X> visitor); private  Either(); abstract LeftProjection<A, B> left(); abstract RightProjection<A, B> right(); abstract X fold(Match<A, B, X> visitor); abstract X fold(Function<? super A, ? extends X> left, Function<? super B, ? extends X> right); abstract boolean isLeft(); abstract boolean isRight(); static Either<A, B> left(final A left); static Either<A, B> right(final B right); }
Either { public abstract <X> X fold(Match<A, B, X> visitor); private  Either(); abstract LeftProjection<A, B> left(); abstract RightProjection<A, B> right(); abstract X fold(Match<A, B, X> visitor); abstract X fold(Function<? super A, ? extends X> left, Function<? super B, ? extends X> right); abstract boolean isLeft(); abstract boolean isRight(); static Either<A, B> left(final A left); static Either<A, B> right(final B right);  }