Create a gist now

Instantly share code, notes, and snippets.

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