Is there something like a “double extension method...
# getting-started
r
Is there something like a “double extension method”, as in inside of a scope, an extension method becomes available on something else? Basically, kotlin-result has this interface:
Copy code
public interface CoroutineBindingScope<E> : CoroutineScope {
    public suspend fun <V> Result<V, E>.bind(): V
}
Is there a way to add a
bindNullable()
extension function for
T?
that returns
T
or throws, but that is only available inside that scope? I can do it as a function, something like
CoroutineBindingScope.bindNullable(T?)
, but is it possible to do this as a method?
j
If you're targeting the JVM only, there is an experimental feature called context receivers that you can try. Basically it would look something like this:
Copy code
context(CoroutineBindingScope<E>)
suspend fun <E, V> Result<V, E>.bindNullable(): V {
    // ...
}
But note that this requires enabling the feature with a compiler argument.
(Note that this feature is being reworked and rebranded as "Context Parameters", so expect changes in the future)
r
Thanks, that looks really interesting! I’m writing a mix of KMP and Android code, so I’ll stick with the function for now. Do you have a guess when Context Parameters will work for js/swift as well?
j
Despite the
[JetBrains]
tag, I'm not part of the Kotlin team, I'm just a humble user 😅 so I don't really know when this is planned. I believe the priority for them was to stabilize K2 so far, hence why this kind of complex feature didn't get much traction, but now the efforts on those features are resuming little by little. That being said, this feature is very complex so it will take some time
👍 1
d
Please don't use context receivers, as they planned to be replaced with context parameters in incompatible way quite soon (around 2.1.20) More info in the discussion here: https://github.com/Kotlin/KEEP/issues/367
d
What's the estimated date for 2.1.20?
d
Every major (
2.X.0
) release happens after ~6 months after the previous one So 2.1.20 will be approximately in August-September of 2025
k
2025?
👌 1
d
So a year from now? That’s not really soon for some people.
k
then 2.2.20? or I don't get the calculation 🙂
d
I suspect it was a typo.
d
Oh, sorry, I messed up with dates indeed 2.1.20 will be released in March-April of 2025 by the current schedule
d
You mean 2024?
d
The current year is 2024, right? So nothing new cannot be released in spring of 2024
d
Oh right, I didn't see the months 😉
👌 1
Though 6 months from the last release would be November 2024, which I think is why Jakub and I got confused.
j
I think what Dmitriy meant is that 2.1.0 would be 6 months from 2.0.0, but that doesn't say anything about .10 and .20 releases
👌 1
d
Yeah 2.1.20 will be in ~6 months after 2.0.20 And 2.0.20 will be released quite soon (2.0.20-RC was released today)
👌 1
d
Ah, that was the confusion! Is the release cadence documented anywhere? Also, is there any semantic meaning behind ".10" and ".20" release numbering?
d
It's described here The doc doesn't mention .10 releases, they includes only fixes to major problems found in corresponding .0 release