Last active
September 16, 2019 12:42
-
-
Save leopku/7ecd658f2260030182251755eea8ed14 to your computer and use it in GitHub Desktop.
Check a deep nest object properties in an elegant(Functional Programming) way.
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
Optional.ofNullable(product).map( | |
Product::getLatestVersion | |
).map( | |
ProductVersion::getProductData | |
).map( | |
ProductData::getTradeItem | |
).map( | |
TradeItemType::getInformationProviderOfTradeItem | |
).map( | |
PartyInRoleType::getGln | |
).orElse(null); | |
int entryListSize = io.vavr.control.Option.of(dataResponse) | |
.map(Response::data) | |
.map(FetchEntriesOfFeedQuery.Data::feed) | |
.map(FetchEntriesOfFeedQuery.Feed::entries) | |
.map(List::size) | |
.getOrElse(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Lambda needs the API of Android >= 24.