Hey guys, I'm trying to create a nice structure of...
# announcements
r
Hey guys, I'm trying to create a nice structure of states of data I'm getting from the server and I don't know how not to repeat all the constructor parameter(s) for each case? Here's an example where I have to add the parameter
value: Value
to the constructor of each subclass. Any idea how to make this nicer? Thanks!
Copy code
sealed class BaseStatus(
    open val value: Value?
)

data class LoadingStatus(
    override val value: Value?
) : BaseStatus(value)

data class DoneStatus(
    override val value: Value
) : BaseStatus(value)

data class ErrorStatus(
    val error: Throwable,
    override val value: Value?,
    var consumed: Boolean = false
) : BaseStatus(value)
s
Copy code
sealed class BaseStatus {
    abstract val value: Value?
}

data class LoadingStatus(
    override val value: Value?
) : BaseStatus()

data class DoneStatus(
    override val value: Value
) : BaseStatus()

data class ErrorStatus(
    val error: Throwable,
    override val value: Value?,
    var consumed: Boolean = false
) : BaseStatus()
@Rok Koncina I replace the
(...)
with
{ ...}
in the sealed class, and you’ll have a little less typing
g
Value should be abstract
s
Yep!
g
Anyway, +1 to this approach