im getting this warning, but i'm not sure if there...
# getting-started
b
im getting this warning, but i'm not sure if there's a way to put an explicit label on a receiver?
k
How about:
Copy code
fun <T> Sequence<T>.repeat(count: Int) = this.let { seq ->
   sequence { repeat(count) { yieldAll(seq) } }
}
Alternatively:
Copy code
fun <T> Sequence<T>.repeat(count: Int) = generateSequence { this }.take(count).flatten()
b
those are nice workarounds, but does that mean there's no way to explicitly label the reciever/outer function?
(as the tooltip says)
k
Sorry, I don't know if this is possible. How did you get that tooltip? It doesn't show in my editor. Are you using K1 or K2 mode? I assume the issue it's highlighting is related to this: https://youtrack.jetbrains.com/issue/KTLC-82/Qualified-this-change-behavior-in-case-of-potential-label-conflicts Also, I think that tooltip is wrong: there is no ambiguity here because
this@repeat
can only refer to the
Sequence<T>.repeat
function. It can't possibly refer to the regular Kotlin
repeat
function because its second parameter (i.e. the lambda) doesn't take a receiver - it has only an
it
, not a
this
.
b
strange, i believe i'm using K1
i just have this function `
Copy code
fun <T> Sequence<T>.repeat(count: Int) = sequence { repeat(count) { yieldAll(this@repeat) } }
and the ide (idea ultimate) is highlighting it as in the screenshot
e
you can give explicit labels to lambdas, https://kotlinlang.org/docs/returns.html#return-to-labels
Copy code
sequence { repeat(count) repeat@{ yieldAll(this@repeat) } }
in this case I don't think that's the behavior you want though
b
just saw your response, that would indeed refer to the wrong thing in my case (i'm targeting the outermost receiver). i believe Klitos is correct and the warning is just given incorrectly.