This project aims to refine a Result type for Java.
The Result<T, E>
type is nothing new. It's part of the rust standard library. It's also very similar in nature to the Either<L, R>
type, which is part of the scala standard library and available for the Java Programming Language most famously via the vavr library. Either however is more generic than Result. It just means "either left or right" after all. Only by convention do we denote Left
as the failure and Right
as the success case. Result on the other hand enforces this policy. It's a specialized kind of Either, with Failure
and Success
instead of Left
and Right
. It clearly communicates to a human looking at the definition of an operation that it might fail or succeed.
More of an experiment right now than a "solid library" (also, only available here on github as of now). These are the available types:
Result<T, E>
: A Result is either a Success or a Failure, these are its two cases. It is meant to be used as a means to communicate that the respective operation may succeed or fail. Its monadic structure strongly encourages* treating failure as a first class citizen.Done
**: This type is meant to be used in conjuction with e.g. Result to signal a successfully completed operation without a corresponding value.
* The api currently provides unsafeGet()
and unsafeGetError()
for testing convenience, but they might very well be removed in future versions.
** Based on akka.Done.