Last active
July 7, 2016 04:58
-
-
Save afcastano/80783aeef3bc8478cb4f280e9c865335 to your computer and use it in GitHub Desktop.
Add two optionals using bind and unit functions.
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
public Optional<Integer> optionalAdd(Optional<Integer> val1, Optional<Integer> val2) { | |
return | |
val1.flatMap( first -> | |
val2.flatMap( second -> | |
Optional.of(first + second) | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment