Skip to content

Instantly share code, notes, and snippets.

@kijanowski
Created November 1, 2018 18:56
Show Gist options
  • Select an option

  • Save kijanowski/97bc4af1fd3f1504e3d6a4babdcc1b1a to your computer and use it in GitHub Desktop.

Select an option

Save kijanowski/97bc4af1fd3f1504e3d6a4babdcc1b1a to your computer and use it in GitHub Desktop.
legacyNullCheck
// 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