Created
November 1, 2018 18:56
-
-
Save kijanowski/97bc4af1fd3f1504e3d6a4babdcc1b1a to your computer and use it in GitHub Desktop.
legacyNullCheck
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 String legacyNullCheck(String nullableValue) { | |
| if (nullableValue != null) { | |
| return nullableValue.toLowerCase(); | |
| } | |
| return nullableValue; | |
| } | |
| // do it the functional way | |
| public String vavrNullCheck(String nullableValue) { | |
| return Option.of(nullableValue) | |
| .map(String::toLowerCase) | |
| .getOrElse(nullableValue); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment