You are currently viewing Create new sealed class from a sub selection of its members

Create new sealed class from a sub selection of its members

Is it possible to create a new sealed class from its members, somehow like Typescript’s Pick?

It would be nice to have that for error handling. In my current project, I have a sealed class called Error, that contains data classes. On each screen where the error should be displayed, I would have a list (or a single variable, depending if pattern matching on lists is not possible) with the Error sealed class as its type.

Now it would be great to only handle some errors on each screen and do a pattern match on that list. To be able to handle only some errors on a screen, I would need to select and collect them in a new sealed class, so that the pattern match fails when a case was forgotten.

Does anyone know if that is possible in Kotlin?

submitted by /u/St-IGNUcius
[link] [comments]