Hi Aaron, thank you for your kind words.
Not sure I can think of an example in which a ‘state within a state’ is possible, so my suggestion would be to ‘flatten’ the states if possible.
Let’s consider a trivial scenario where we have a state-within-a-state modelled with two sealed classes:
sealed class A(open val b: B) {
data class A1(override val b: B) : A(b)
data class A2(override val b: B) : A(b)
}
sealed class B {
object B1: B()
object B2: B()
}
To flatten these states into something a single state-machine could represent, we’d have to use the product of the two classes:
sealed class AB {
object A1B1 : AB()
object A1B2 : AB()
object A2B1 : AB()
object A2B2 : AB()
}
Obviously, this works well for a minimal number of states but grows exponentially with the more you need to track. If you have a specific example you’d like me to examine, do let me know.