package pl.mg6.likeornot.commons

fun <T> List<T>.chunk(chunkSize: Int): List<List<T>> {
    require(chunkSize > 0) { "chunkSize must be greater than 0" }
    val chunksCount = (size + chunkSize - 1) / chunkSize
    val chunkedList = ArrayList<List<T>>(chunksCount)
    for (i in 0 until size step chunkSize) {
        chunkedList.add(subList(i, minOf(i + chunkSize, size)))
    }
    return chunkedList
}

package pl.mg6.likeornot.commons

fun <T> List<T>.chunk(chunkSize: Int): List<List<T>> {
    require(chunkSize > 0) { "chunkSize must be greater than 0" }
    val chunksCount = (size + chunkSize - 1) / chunkSize
    val chunkedList = ArrayList<List<T>>(chunksCount)
    for (fromIndex in 0 until size step chunkSize) {
        val toIndex = minOf(fromIndex + chunkSize, size)
        chunkedList.add(subList(fromIndex, toIndex))
    }
    return chunkedList
}

Rename to fromIndex, extract toIndex.
[refactoring] Rename to fromIndex, extract toIndex.

mg6maciej/fluffy-octo-rotary-phone,mg6maciej/fluffy-octo-rotary-phone,mg6maciej/fluffy-octo-rotary-phone