Skip to content

Instantly share code, notes, and snippets.

@LeifW
Last active August 16, 2017 03:35
Show Gist options
  • Save LeifW/00a4cde32232516fd1a0f827707f7b32 to your computer and use it in GitHub Desktop.
Save LeifW/00a4cde32232516fd1a0f827707f7b32 to your computer and use it in GitHub Desktop.
Optional / Either / CompletableFuture similarities
Optional Either CompletableFuture
Create success value Optional.of Either.right CompletableFuture.completedFuture
Create failure value Optional.empty Either.left f = new CompletableFuture(); f.completeExceptionally; return f
Apply function to success case .map .map .thenApply
Apply a function to success case that may also fail .flatMap .flatMap .thenCompose
Handle both failure & sucess cases at once .map().orElse() .fold .handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment