chunked

Splits the given flow into a flow of non-overlapping lists each not exceeding the given size but never empty. The last emitted list may have fewer elements than the given size.

Example of usage:

flowOf("a", "b", "c", "d", "e")
.chunked(2) // ["a", "b"], ["c", "d"], ["e"]
.map { it.joinToString(separator = "") }
.collect {
println(it) // Prints "ab", "cd", e"
}

Throws

if size is not positive.