Created
April 25, 2020 10:04
-
-
Save arindam89/e8c79d524a1092d8bdc56a9b4ecf8257 to your computer and use it in GitHub Desktop.
Either Example
This file contains 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
// = Right(result) or Left(exception) | |
Either<Exception, Integer> divideEither(Integer dividend, Integer divisor) { | |
try { | |
return Either.right(dividend / divisor); | |
} catch (Exception e) { | |
return Either.left(e); | |
} | |
} | |
@Test | |
public void createEither() { | |
System.out.println(divideEither(10,2)); | |
System.out.println(divideEither(10,0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment