Created
April 1, 2018 20:02
-
-
Save mjedynak/34e3f2fa2ab8fa1221685c2f4925a02c 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 class CityRetrieverWithOptional { | |
private final PersonService personService; | |
public Optional<String> retrieveCity(String name) { | |
return Optional.ofNullable(personService.getByName(name)) | |
.map(Person::getAddress) | |
.map(Address::getCity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment