Skip to content

Instantly share code, notes, and snippets.

@benweidig
Created May 16, 2020 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benweidig/0a01e7ba981bdf01fd16e2334b6230e6 to your computer and use it in GitHub Desktop.
Save benweidig/0a01e7ba981bdf01fd16e2334b6230e6 to your computer and use it in GitHub Desktop.
public void doWork(List<MyBean> beans) {
beans.stream()
.map(this::mapToItem)
.forEach(this::workOnItem);
}
private MyItem mapToItem(MyBean bean) {
try {
MyItem item = ...;
return item;
}
catch (ValidationException e) {
// handle appropriately
}
return null;
}
private void workOnItem(MyItem item) {
if (item == null) {
return;
}
try {
// do some work that might throw
}
catch (IOException e) {
// handle appropriately
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment