Created
September 17, 2018 16:27
-
-
Save Serchinastico/d44c6321dee7d6312b0e6b7cacd8c8fb to your computer and use it in GitHub Desktop.
fold 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 the set of products that were ordered by every customer | |
fun Shop.getSetOfProductsOrderedByEveryCustomer(): Set<Product> { | |
val allProducts = customers.flatMap { it.orders.flatMap { it.products } }.toSet() | |
return customers.fold(allProducts) { acc, customer -> | |
acc.intersect(customer.orders.flatMap { it.products } ) | |
}.toSet() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment