Skip to content

Instantly share code, notes, and snippets.

@arindam89
Created April 25, 2020 10:04
Show Gist options
  • Save arindam89/e8c79d524a1092d8bdc56a9b4ecf8257 to your computer and use it in GitHub Desktop.
Save arindam89/e8c79d524a1092d8bdc56a9b4ecf8257 to your computer and use it in GitHub Desktop.
Either Example
// = 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