Created
November 28, 2014 17:27
-
-
Save rupertbates/7d2bbf7cea695ee002d6 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
//Checking for null through an object graph quickly becomes unwieldy | |
if (article.getContributor() != null && | |
article.getContributor().getImage() != null && | |
article.getContributor().getImage().getSize() != null) { | |
Size size = article.getContributor().getImage().getSize(); | |
setContributorImageSize(size.getWidth(), size.getHeight()); | |
} | |
//Chaining multiple optional values using bind and map | |
article.getContributor() | |
.bind(Contributor::getImage) | |
.map(DisplayImage::getSize) | |
.map(size -> setContributorImageSize(size.getWidth(), size.getHeight())); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment