Method Delegation with Parameter Defaults

It’s not uncommon for me to have a method with a default, and then to write another method that calls it, and then the default ends up having to be defined in multiple places, which ends up feeling annoying.

Just to give myself a toy example:

fun orderBurger(patty: Patty = Patty.BEEF, cheese: Bool = false, toppings: List<Topping> = listOf<Topping>()) {
   // impl goes here
}

Now, I have to order bacon burgers a fair amount, so I want a convenience method that adds a bacon topping. I still want the the option of changing the patty or adding cheese, but there’s no way to define orderBaconBurger that respects the defaults already specified on orderBurger – I have to redefine the defaults here:

fun orderBaconBurger(patty: Patty = Patty.BEEF, cheese: Bool = false) {
   orderBurger(patty, cheese, listOf(Topping.BACON))
}

I can’t simply make these fields optional and then specify then in the orderBurger call, because these nulls will actively replace the defaults in orderBurger.

I know this is a toy example, but am I missing a good strategy for avoiding this duplication? I feel like this comes up a fair amount and irritates me each time. I encountered the same problem in Scala and I didn’t have a great solution for it there either AFAICR.

https://youtrack.jetbrains.com/issue/KT-18695

Not sure how long it will take for this to be worked on. Maybe someone should write up a KEEP with some possible options to solve this kind of issue.