https://kotlinlang.org logo
#announcements
Title
# announcements
d

danneu

02/11/2017, 6:00 AM
last one is the simplest
Copy code
fun <T> Iterable<T>.batch(chunkSize: Int) = this
        .mapIndexed { i, item -> i to item }. // create index value pairs
        .groupBy { it.first / chunkSize }.    // create grouping index
        .map { it.value.map { it.second } }   // split into different partitions
❤️ 1
m

max.cruz

02/11/2017, 5:07 PM
danneu: Wonderful, thanks. I was thinking in a functional way to split an array in chunks 👍
2 Views