ambivalence
<dependency>
<groupId>com.codepoetics</groupId>
<artifactId>ambivalence</artifactId>
<version>0.2</version>
</dependency>
An Either type for Java 8, in case you needed one.
Features:
joinandforEitherto access values safely.- left and right projections, with
mapandflatMap. equals,hashCodeandtoStringimplemented.Tryablewraps an exception-throwing lambda so that it returnsEither<T, Exception>.EithersprovidesStreamcollectors which split a stream ofEithervalues and optionally collect the left values.
Either<String, Integer> stringOrInt1 = Either.ofLeft("a string");
Either<String, Integer> stringOrInt2 = Either.ofRight(23);
System.out.println(stringOrInt1.join(String::toUpperCase, Object::toString)); // prints "A STRING"
System.out.println(stringOrInt2.join(String::toUpperCase, Object::toString)); // prints "23"