Johann Pardanaud
08/25/2023, 9:21 AMcontext(String)
val foo = {
println(toString())
}
val foo = context(String) {
println(toString())
}
Robert Williams
08/25/2023, 9:34 AMcontext(String)
val foo get() = {
println(toString())
}
Robert Williams
08/25/2023, 9:34 AMCLOVIS
08/25/2023, 11:34 AMval foo: context(String) () -> Unit = {
println(toString())
}
Johann Pardanaud
08/25/2023, 12:27 PMJohann Pardanaud
08/25/2023, 12:30 PMval print: context(String) () -> Unit = {
println(toString())
}
It works well but I cannot call it with a context receiver:
with("hello") {
print()
// ^ Error: No value passed for parameter 'p1'
}
I must pass the context as a parameter:
print("hello")
Is this the only way?CLOVIS
08/25/2023, 12:31 PMJohann Pardanaud
08/25/2023, 12:31 PMIt seems similar to the behavior of regular receivers, where lambdas can accept them as regular parameters instead.Oh I did not know that actually!
CLOVIS
08/25/2023, 12:32 PMJohann Pardanaud
08/25/2023, 12:34 PMIt is just a prototype, after all.Yeah, I'm okay with this and I'm not expecting much. I'm just taking a look at context receivers to explain to people why we can't use them right now 😅
Johann Pardanaud
08/25/2023, 12:34 PMJohann Pardanaud
08/25/2023, 12:34 PMCLOVIS
08/25/2023, 12:34 PMYoussef Shoaib [MOD]
08/25/2023, 4:14 PMcontext(A) operator fun <A, R> (context(A) () -> R).invoke(): R = this(this@A)
Johann Pardanaud
08/25/2023, 5:08 PM