I hate to ask this... is there a one-line way of g...
# announcements
v
I hate to ask this... is there a one-line way of getting the first half of a list for a forEach loop? And then the second half of the list?
b
Copy code
list.take(list.size / 2).forEach { 
   // first half
}
and
Copy code
list.drop(list.size / 2).forEach {
   // second half
}
👍 3
a
This will have O(n) memory impact
b
use
.asSequence()
before `take`/`drop` to avoid that
a
Yep,
asSequence()
will do the trick.