Skip to content

Instantly share code, notes, and snippets.

@kijanowski
Last active November 4, 2018 19:14
Show Gist options
  • Save kijanowski/a811693fc068e27963b0e5865695956b to your computer and use it in GitHub Desktop.
Save kijanowski/a811693fc068e27963b0e5865695956b to your computer and use it in GitHub Desktop.
nullConditionalExecution
// instead of
public void legacyNullConditionalExecution(String nullableValue) {
if (nullableValue != null) {
exec.methodOne(nullableValue);
}
}
// do it the functional way
public void vavrNullConditionalExecution(String nullableValue) {
Option.of(nullableValue)
.forEach(exec::methodOne);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment