julian
10/17/2021, 6:35 AMCoproduct
? How come? And what's the recommended alternative?raulraja
10/18/2021, 8:40 AMsealed interface MyResult
data class StringValue(val value: String): MyResult
object MyCustomModel : MyResult
fun foo(): MyResult = StringValue("ok")
fun foo(): StringValue = StringValue("ok")
fun foo(): MyResult = MyCustomModel
In this case you only incur in allocation for the String case but when you use the Coproduct data type you wrap all cases.
In the future we should be able to do something like
fun foo(): String | MyCustomModel = "ok"
fun foo(): String | MyCustomModel = MyCustomModel
but we are not there yet and we dropped Coproduct because it would quickly become a bad alternative encoding to this problem.
If there is anything we can do to help you migrate out of Coproduct please ping me, happy to help.julian
10/18/2021, 5:24 PMraulraja
10/18/2021, 6:00 PM