Created
September 17, 2018 16:00
-
-
Save Serchinastico/3ed107ad6536febd3a85cc9db3de5295 to your computer and use it in GitHub Desktop.
flatmap koan
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
// Return all products this customer has ordered | |
val Customer.orderedProducts: Set<Product> get() { | |
return orders.flatMap { it.products }.toSet() | |
} | |
// Return all products that were ordered by at least one customer | |
val Shop.allOrderedProducts: Set<Product> get() { | |
return customers.flatMap { it.orderedProducts }.toSet() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment