Skip to content

Instantly share code, notes, and snippets.

@rnaufal
Created March 6, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnaufal/08c64a225d47150b371a66a72890269e to your computer and use it in GitHub Desktop.
Save rnaufal/08c64a225d47150b371a66a72890269e to your computer and use it in GitHub Desktop.
Collection<Car> allPeopleCars = people
.stream()
.map(Person::getCars)
.flatMap(mayHaveCars -> mayHaveCars.map(Collection::stream).orElseGet(Stream::empty))
.collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment