Last active
November 4, 2018 19:15
-
-
Save kijanowski/5673d02fe05065a932119f6b62e78adc to your computer and use it in GitHub Desktop.
conditionalException
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 legacyConditionalException(String nullableValue) { | |
| if (nullableValue != null) { | |
| exec.methodOne(nullableValue); | |
| } else { | |
| throw new RuntimeException("don't like nulls"); | |
| } | |
| } | |
| // do it the functional way | |
| public void vavrConditionalException(String nullableValue) { | |
| Option.of(nullableValue) | |
| .peek(exec::methodOne) | |
| .getOrElseThrow(() -> new RuntimeException("don't like nulls")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment