IIUC, that would turn the for
comprehension into a syntactic context inside of which every call to the “expand” operator would be replaced with a binding at the for
comprehension level of the expression with an auxiliary variable. E.g. that would desugar to:
for {
x<- randomUUID
user <- createUser(User(name, x))
} yield user
A general solution to this would just mean running through each point in a for
comprehension, and analysing the expression on the right of the <-
to extract each “inlined” wrapped type as a flatMap
, before the expression. It may need to be inside a for-comprehension, which sets the scope at which that binding is extracted. It could very well be implementing as part of the desugaring of the for comprehension itself.
This is a very interesting idea, and it seems closer to the deep-nested-code analysis and transformation that the macros of monadless
or dotty-cps-async
. From my first view, it has a lot of merit as a separate proposal.