Created
February 28, 2013 11:21
-
-
Save karad/5056064 to your computer and use it in GitHub Desktop.
Either Utility for Play framework F.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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