https://kotlinlang.org logo
#android
Title
# android
m

mg6maciej

03/13/2017, 10:58 AM
Nevertheless I don't like overuse of
apply
or
also
and I tend to avoid it unless it makes the code way more readable.
Copy code
val chunkedList = ArrayList<List<T>>(chunksCount)
    for (i in 0 until size step chunkSize) {
        chunkedList.add(subList(i, minOf(i + chunkSize, size)))
    }
    return chunkedList
vs
Copy code
return ArrayList<List<T>>(chunksCount).also {
        for (i in 0 until size step chunkSize) {
            it.add(subList(i, minOf(i + chunkSize, size)))
        }
    }
1️⃣ 1
2️⃣ 3