Karlo Lozovina
10/19/2021, 8:59 PMsomeCollection.take(42).forEach { /* ... */ }
is there a way to access the collection inside the forEach that the forEach is iterating over?Damian Zawadzki
10/19/2021, 9:04 PMsomeCollection
.take(42)
.let{ collection ->
collection.forEach { item->
// access to collection and item
}
}
maybe something like this?Karlo Lozovina
10/19/2021, 9:14 PMit
...Damian Zawadzki
10/19/2021, 9:22 PMsomeCollection
.take(42)
.collectionForEach { collection, item ->
// access to collection and item
}
//its modified original forEach extension
public inline fun <T> Iterable<T>.collectionForEach(action: (Iterable<T>, T) -> Unit): Unit {
for (element in this) action(this, element)
}
But the question is, do you realy need it ? 🙂Marcus Brito
10/19/2021, 9:30 PMsomeCollection
will be in scope anywayJoffrey
10/19/2021, 9:31 PMtake(42)
, not the original oneMarcus Brito
10/19/2021, 9:31 PMKarlo Lozovina
10/19/2021, 10:18 PMDamian Zawadzki
10/19/2021, 10:29 PM