
When calling the function, the client code can choose to specify a value or just use the default. This is a feature in many programming languages where a developer can specify a default value for a parameter. Many people have probably heard of default arugments. It’s a lot nicer because you can instantly see what each value in the function is doing. In the above code snippet, the developer calls each argument in the function by it’s name and assigns a value to the parameter. Here is a little Python to show off named arguments. This was something I really enjoy in Python but isn’t supported in Java.įor those people who aren’t familiar with the term, named arguments is a feature in a programming language where a developer can specify the name of a parameter and assign it a value when calling a function. Once customers.sumBy returns, we have a count of the total number of times the specified product was ordered.Kotlin does indeed use default arguments and named parameters. The it.orders.sumBy returns a number that gets fed into customers.sumBy. The it.unt returns a number that gets fed into it.orders.sumBy.

Once I was traversing orders, I could do a count operation on products and get a total of how many products matched my predicate. Inside of the lambda, I did another sumBy operation on orders. I needed two sumBy operations to solve this problem. Get Customers Who Ordered Productįun Shop.getCustomersWhoOrderedProduct(product: Product): Set Ī customer has a one to many relationship with orders, and orders have a one to many relationship with products.

While doing this, I got to revist the Elivis operator (?:), map, maxBy, sumBy, filter, count, and toSet.

I had to solve three different problems using the collections API. This portion of the Kotlin Koans tutorial appeared to be a review of the concepts I had been working on throughout the collection section.
