Skip to content

Instantly share code, notes, and snippets.

@mchmielarz
Created March 14, 2019 22:32
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 mchmielarz/dc2f3efb0bdd7b73bd8cfeb18d8a9001 to your computer and use it in GitHub Desktop.
Save mchmielarz/dc2f3efb0bdd7b73bd8cfeb18d8a9001 to your computer and use it in GitHub Desktop.
for-comprehension: Combining parts into a car using flatMap
final Option<Car> ourShinyCar =
body().flatMap(
b -> engine().flatMap(
e -> wheels().map(
w -> new Car(b, e, w)
)
  )
 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment