Created
May 16, 2020 16:52
-
-
Save benweidig/0a01e7ba981bdf01fd16e2334b6230e6 to your computer and use it in GitHub Desktop.
This file contains 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
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