Emil Kantis
12/02/2022, 10:02 AMsealed interface
should be data types? sealed data interface
could perhaps be a nice addition? I would like to use copy
with the subtypes.. 🙂 apologies for the low-effort proposal.. just want to get some discussion ✌️Davio
12/02/2022, 10:09 AMCopyable
, so I wonder if it would make sense or even be possible to generate the byte code for data classes in such a way that they all implement this interface.
If that were the case, you could write your sealed interface like so: sealed interface Foo : Copyable
and both data classes or other classes implementing this interface would work for itsimon.vergauwen
12/02/2022, 10:14 AMabstract val
in the sealed class
though.
Since at the level of Foo
you need to know which properties are common so they can be copied.
Optics solves these problem but would love to have something in the language instead of external support.
They touch upon it in the https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md KEEP.Davio
12/02/2022, 10:28 AMmyObj.copy(name = "something different")
that makes it a lot more tricky than I thoughtDavio
12/02/2022, 10:32 AMcopy
method has a different signature whereas functions like equals, toString and hashCode
always have the same signaturemcpiroman
12/02/2022, 12:47 PMcopy()
with no parameters 🤔Kroppeb
12/02/2022, 4:23 PMcopy
method to the interface and in each data class add fun copy() = copy()
... errr, wait, that doesn't work