either

The missing Either and Try types for Java 8+

Implementation of the Either and Try types for Java 8+ based on the Scala Either and Try types.

Either is a type that represents a value of 1 of 2 possible types (disjoint union). An instance of Either is an instance of either Left or Right.

Conventionally, Either is used as a replacement for Optional: instead of having an empty Optional, a Left that contains useful information is used, while Right contains the successful result.

While Either is right-biased, it is possible to operate on the left values by using a LeftProjection, obtained by invoking the Either#left() method.

The Try type represents a computation that may either result in an exception, or return a successfully computed value. It’s similar to, but semantically different from the Either type.

Instances of Try, are either an instance of either Success or Failure.

Releases

The latest release is available on Maven Central.

implementation 'io.github.2bllw8:either:3.4.0'

Maven Central