简单的问题,是否有一种方法可以让集合对每个元素(如foreach)应用操作,但返回列表
我可以自己写:
public inline fun <T> Iterable<T>.myforEach(action: (T) -> Unit): Iterable<T> {
for (element in this) action(element)
return this
}
但它必须已经存在
There is onEach for this:
val sameList = list.onEach { doStuff() }