Skip to content

Instantly share code, notes, and snippets.

@karad
Created February 28, 2013 11:21
Show Gist options
  • Save karad/5056064 to your computer and use it in GitHub Desktop.
Save karad/5056064 to your computer and use it in GitHub Desktop.
Either Utility for Play framework F.java
package libs.f;
import static play.libs.F.Option.*;
import play.libs.F.Either;
import play.libs.F.Option;
/**
* Either Utility for Play framework F.java
*
* @author kazuhiro hara (http://greative.jp)
*/
public class EitherUtil {
/**
* Make both same type Either
* @param error Error value
* @param result Success value
* @param <A> Any type
* @return
*/
public static <A> Either<A, A> apply(A error, Option<A> result) {
if(result.isDefined()) {
return Either.Right(result.get());
} else {
return Either.Left(error);
}
}
/**
* Get result all content. (ex. Result
* @param result Either value
* @param <A> Any type
* @return
*/
public static <A> Option<A> getResult(Either<A, A> result) {
if(result.right.isDefined()) {
return result.right;
}
if(result.left.isDefined()) {
return result.left;
} else {
return None();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment