Is there a method in the standard library to short...
# announcements
l
Is there a method in the standard library to shorten this code?
Copy code
items.forEach {
    it.apply {
        ...
    }
}
t
You can write your own extension for this case :
Copy code
inline fun <T> Iterable<T>.each(block: T.() -> Unit) {
    for (el in this) {
        el.block()
    }
}
Usage :
Copy code
listOf("Hello", "World").each { // this: String
    println(length)
}
l
Yes well… I mostly asked to know if I really needed to 😆