Skip to content

poetix/ambivalence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ambivalence

Build Status

<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:

  • join and forEither to access values safely.
  • left and right projections, with map and flatMap.
  • equals, hashCode and toString implemented.
  • Tryable wraps an exception-throwing lambda so that it returns Either<T, Exception>.
  • Eithers provides Stream collectors which split a stream of Either values 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"

About

Either for Java 8

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages