Skip to content

Instantly share code, notes, and snippets.

Created Oct 8, 2016
What would you like to do?
public Optional<Dinner> makeDinner(GrillService service) {
Optional<Charcoal> charcoal = service.getCharcoal();
Optional<Lighter> lighter = service.getLighter();
Optional<CornCob> cornCob = service.getCornCob();
return Stream.of(charcoal, lighter, cornCob).allMatch(Optional::isPresent)
? service.lightFire(charcoal.get(), lighter.get()).flatMap(fire -> service.grill(fire, cornCob.get()))
: Optional.empty();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment