I have functions that represent steps in a process. Each function also knows the next step, if any. I would like to be able to do something like:
fun fooStep() : Step? {
... do something ...
return ::barStep
}
These functions are called from a central dispatch function that contains code similar to this:
var step = startStep
while (step != null) {
step = step()
}
Note that the logic at a particular step also determines the next step, if even one.
I thought I could determine Stephow:
typealias Step = () -> Step?
So, Stepthis is a function that returns another Stepor null. However, this cannot be compiled with:
Kotlin: Recursive type alias in expansion: Step
I can get around this by wrapping the function in an object. eg:
data class StepWrapper(val step: () -> StepWrapper?)
and accordingly changing the function signatures.
, , (: ::barStep), StepWrapper:
fun fooStep() : StepWrapper? {
... do something ...
return StepWrapper(::barStep)
}
( , .)
-, . ?