Skip to content

A Result type for the Java Programming Language

License

Notifications You must be signed in to change notification settings

hekmekk/result4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Result type for Java

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.

The current state

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.

About

A Result type for the Java Programming Language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages