Skip to content

Instantly share code, notes, and snippets.

@Serchinastico
Created September 17, 2018 16:00
Show Gist options
  • Save Serchinastico/3ed107ad6536febd3a85cc9db3de5295 to your computer and use it in GitHub Desktop.
Save Serchinastico/3ed107ad6536febd3a85cc9db3de5295 to your computer and use it in GitHub Desktop.
flatmap koan
// 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