onEach

Performs the given action on each element and returns the array itself afterwards.

inline fun <T> Array<out T>.onEach(action: (T) -> Unit): Array<out T>(source)
val fruits = arrayOf("Apple", "Banana", "Cherry")

// Perform an action on each element and get the original array back
val sameArray = fruits.onEach { println("Processing: $it") }

// The returned array is the same instance as `fruits`
println(sameArray.contentToString())  // [Apple, Banana, Cherry]

Source