Does anyone have any good, solid code examples whe...
# random
t
Does anyone have any good, solid code examples where you'd use a context receiver over an extension function?
r
Here's a practical example: https://github.com/vert-x3/vertx-lang-kotlin/issues/194#issue-848232394 In order to adapt Vert.x routers to accept suspend functions you need to create your own wrapper. The most popular method is described in the issue, however, it will not compile without an explicit
CoroutineScope
. This means that, without context receivers, you need to copy that method to each verticle or class, but with context receivers you can create a common
Route.coroutineHandler
t
That's cool, but in reality if that's the best practical example out there, it's seriously not worth adding this feature. The use case for using context receivers seems to be very slim. Context receivers will (in my opinion) take away from the language's readability and elegancy.
r
Lol, I'd much rather get union typing or actual package private visibility, but context receivers seem to be what people want. I just hope they change the syntax. 😞
t
What syntax idea do you have in mind? 🤔