Endre Deak
02/15/2023, 8:51 PMcopy
method?
data class Foo(val bar: String)
val foo = Foo("bar")
foo.copy(bar = "bar1") // current
// could be this:
foo.copy {
bar = "bar1"
}
Emil Kantis
02/15/2023, 8:57 PMRuckus
02/15/2023, 8:58 PMfoo.copy(
bar = "bar1"
)
What do the curly braces gain you?ephemient
02/15/2023, 9:03 PMEndre Deak
02/15/2023, 10:21 PMEmil Kantis
02/15/2023, 10:36 PMAlejandro Serrano Mena
02/16/2023, 8:21 AMJoffrey
02/16/2023, 8:40 AMEmil Kantis
02/16/2023, 8:42 AMJoffrey
02/16/2023, 8:43 AMfun copy(block: TheClassBuilder.() -> Unit)
TheClassBuilder
would only call setters that are actually necessary, so if a property is added, it won't break anythingEmil Kantis
02/16/2023, 8:45 AMJoffrey
02/16/2023, 9:00 AMArkadii Ivanov
02/17/2023, 12:00 AMsome.copy(count = some.count + 1)
vs
some.copy { count += 1 }
Alejandro Serrano Mena
02/17/2023, 2:13 PMArkadii Ivanov
02/17/2023, 2:14 PMephemient
02/17/2023, 2:32 PMcopy var
in the language, https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md#copyable-properties-of-immutable-typesJoffrey
02/17/2023, 3:35 PM