Another thing that would be nice is to be able to ...
# compiler
l
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:
Copy code
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…)
e
could make a DSL instead, separating the "build structure" from "execution"
l
It unfortunately doesn't suit my use case where the functions called into
step { … }
are suspending and where I want
step
to return the value of the lambda directly, to avoid needing indirection.
It's impossible to do what I want with plain Kotlin as of Kotlin 1.5
e
if that's what you need them a compiler plugin like compose?
I have written Kotlin/JVM code that inspects its own bytecode to determine what calls and types are in used, but if you need to handle and block conditionals etc. that would probably be too cumbersome
l
We're in #compiler, so yes, I figured out that a compiler plugin would be needed.
Inspecting JVM bytecode is not so viable as my code also targets JS and I'd like it to work on this platform.