Skip to content

Instantly share code, notes, and snippets.

@nachivpn
Last active July 30, 2017 18:26
Show Gist options
  • Save nachivpn/e6bae0f2d2386e2382f393d6a3d5f572 to your computer and use it in GitHub Desktop.
Save nachivpn/e6bae0f2d2386e2382f393d6a3d5f572 to your computer and use it in GitHub Desktop.
EitherPartial.java
public abstract class Either<L, R>{
//used for pattern matching on contained value and processing/transforming it using some function
public abstract <T> T match(Function<L, T> a, Function<R, T> b);
//used to apply/compose functions which accapet a R (right) value and return an Either
//very useful to chain "either computations"
public abstract <S> Either<L, S> bind(Function<R, Either<L, S>> f);
//used to apply a simple generic R to S function on the R value contained inside an Either
//enables re-use of non-Either functions in the Either context
public abstract <S> Either<L,S> fmap(Function<R, S> f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment