`items.onEach`?
# announcements
d
items.onEach
?
l
onEach
still works with
it
d
i guess this depends on what you have in your
apply
d
do you want to treat each element as
this
?
l
Yes, I want to apply something to every element of my collection. So if I could write
items.applyOnEach { this.attribute = "something" }
, that would be great
The method might no exist. I did not find anything worthwhile by googling
d
probably doesn't, just create your own extension
Copy code
fun <T> Collection<T>.applyOnEach(block: T.() -> Unit) {
    this.forEach {
        it.apply(block)
    }
}
a
Or maybe make extension function on
it
to do the applying and pass that to the forEach
l
Yes absolutely, this is easily implementable. I’m just asking if it already exist. I don’t want to add noise in my code
z
I mean, you could do
inline fun <T> Collection<T>.forEachApply(block: T.() -> Unit
like said above, and it would work great
n
items.map { it.attribute = "something" }