s
Untitled.cpp
e
launch { helloWorld() }
looks just as nice. What’s the point on insiting on using
::helloWorld
here?
s
There is no point on using
::helloWorld
here was just a small example. It’s something I come across from time to time, when working receivers. Not only specific to
CoroutineScope
, but also with other DSLs or builders that work with receivers to expose specialised DSL syntax. A better example might be
parZip
from Arrow Fx, where users would like method references. i.e. to constructors of data classes but you cannot due to the
CoroutineScope
receiver. I’ve noticed in the past that some Arrow users go out of there way to redefine methods without the receivers, to be able to pass method references but I’ve never gone that far. Like you suggest I prefer using
helloWorld()
in those cases. I was wondering if this was already discussed before since the Kotlin compiler already support similar mechanisms such as passing
() -> A
where
suspend () -> A
is expected and similarly
() -> A
also fits into
R.() -> A
.
e
That’s an interesting observation. The could be, indeed, a conversion from
R.() -> A
to
() -> A
.