I am curious, in this code: `fun String.asIndex():...
# getting-started
r
I am curious, in this code:
fun String.asIndex(): Int = withIndex().sumBy { ... }
Why does the call to withIndex() not need use "it" or "this" ? <<I am newbie, obviously!>>
m
Because
this
is implicit. You are in the context of a String inside the body of an extension function on String.
So it's equivalent to
fun String.asIndex(): Int = this.withIndex().sumBy { ... }
, but you just don't have to write
this
.
r
Thank you. It took me a bit to figure it was implied, as a new person I was just reading open source code.