Allan Wang
08/06/2020, 10:00 PMchunked
, where the partial window is at the start?
eg with list [1, 2, 3, 4, 5, 6, 7, 8]
, chunked
gives [[1, 2, 3], [4, 5, 6], [7, 8]]
, but I want [[1, 2], [3, 4, 5], [6, 7, 8]]
.
Or do I have to modulo myself and chunk when I know it's a multiple of my chunk window?Allan Wang
08/06/2020, 10:04 PMAllan Wang
08/06/2020, 10:06 PMval rows: MutableList<View> = mutableListOf()
val firstRowCount = contents.size % 4
if (firstRowCount > 0) {
rows.add(createRow(contents.take(firstRowCount)))
}
rows.addAll(contents.drop(firstRowCount).chunked(4) { createRow(it) })
which isn't too bad, but I was hoping for a more stream-like solutionIan Lake
08/06/2020, 10:22 PMAllan Wang
08/06/2020, 10:23 PMNir
08/06/2020, 11:07 PMNir
08/06/2020, 11:09 PMNir
08/06/2020, 11:10 PMNir
08/06/2020, 11:10 PMCollection<T>
instead of Iterable<T>
Nir
08/06/2020, 11:10 PMNir
08/06/2020, 11:11 PMfor sublist in rows.chunked(3))
or whatever