Is there some function like `Array.forEach` that p...
# announcements
a
Is there some function like
Array.forEach
that passes each element as
this
instead of
it
?
s
what would be the difference between passing this or it?
a
Then I could access
it
from outer scope without using labels or explicit parameter names
Otherwise it is shadowed by
it
from
forEach
At the moment I can do:
foo.run { bar.forEach { it.baz = this } }
But I was wondering if it’s possible to do
foo.let { bar.forEach { baz = it } }
m
I assume you don't want to name the parameter to keep it in a single line?
a
Honestly it was still in a single line even with a parameter name. It’s more that I was wondering if it’s possible / available. Also
let { run { baz = it } }
feels more natural in my case.
But I’m curious to hear your comment if it was about keeping it in a single line if you have one 😛
m
if the issue was just
it
being shadowed, I usually go with the named parameter as it helps reading later... but I can always back the "let's see if it's possible" spirit 😄