Last active
November 4, 2018 19:14
-
-
Save kijanowski/afcbf26c64aaf362aa6e669700a50ee5 to your computer and use it in GitHub Desktop.
conditionalExecutionOfDifferentMethods
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
| // instead of | |
| public void legacyConditionalExecutionOfDifferentMethods(String nullableValue) { | |
| if (nullableValue == null) { | |
| exec.methodOne(DEFAULT); | |
| } else { | |
| exec.methodTwo(nullableValue); | |
| } | |
| } | |
| // do it the functional way | |
| public void vavrConditionalExecutionOfDifferentMethods(String nullableValue) { | |
| Option.of(nullableValue) | |
| .peek(exec::methodTwo) | |
| .onEmpty(() -> exec.methodOne(DEFAULT)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment