has there ever been a proposal around deferring to...
# language-proposals
z
has there ever been a proposal around deferring to default values for named params? Use case being that there's cases where you may or may not have a value for a named param, but don't want to write out every possible permutation for function/constructor invocations to allow default values to run
Copy code
data class Foo(val bar: String, val baz: String = "baz")

// somewhere later
val bazValue = getBazValue() ?: Unset
Foo(
  bar = "bar",
  baz = bazValue
)
Unset
(name could be something better) could be a marker to indicate that you want to defer to the default value. Similar to
Unset
. Then you could denote that a value is undefined and basically pretend the argument was never set
3
b
This seems similar to Kotlin/JS's use of
definedExternally
. I bet this wouldn't be too much of a challenge. I love this idea
z
possibly! I'm particularly interested in the context of code gen, where you might generate code that at runtime might not have every argument and you want to say that's ok. Like generating json adapters for data classes and keys that aren't present in the json but you have default values for in the constructor
2
n
Great idea, I think this is necessary