Created
May 29, 2017 19:00
-
-
Save kyryloz/1c04b0971d582e83effd3c7031500f57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { | |
orderedByAll, customer -> | |
orderedByAll.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