Another thing that would be nice is to be able to count how many invocations of a method are done within a scope. The use case is showing how many steps there are.
Example:
val stuff1: Stuff
val stuff2: Something
val nameOfWhatever: String
withLoading("Doing something long") {
stuff1 = step { getStuff(someInput) }
stuff2 = step { getSomething(stuff1) }
nameOfWhatever = step { fetchThing(someInput, stuff2) }
}
In the snippet above, I'd like
withLoading
to know how many calls to
step
there are in the lambda it's been passed, so it can show somewhere "Step 1/3" while
getStuff(…)
is executing.
Currently, it's impossible to do, and having the desired result requires quite a bit of unsafe boilerplate, unsafe in that if I do a mistake like starting with step 3 instead of 1, the compiler won't spot it.
Of course, there'd be concerns about having conditionally called
step { … }
calls, and possible nesting, plus one might want to provide some info to
step
to show on a UI what the next steps are (e.g. their title, some icon…)