arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / chunkN
fun chunkN(n:
Int
, allowFewer:
Boolean
= true):
Stream
<
Chunk
<O>>
Outputs chunks of size n
.
Chunks from the source stream are split as necessary.
If allowFewer
is true, the last chunk that is emitted may have less than n
elements, like shown below.
import arrow.fx.coroutines.stream.*
//sampleStart
suspend fun main(): Unit =
Stream(1,2,3)
.repeat()
.chunkN(2)
.take(6)
.toList()
.let(::println) //[Chunk(1, 2), Chunk(3, 1), Chunk(2, 3), Chunk(1, 2), Chunk(3, 1), Chunk(2)]
//sampleEnd
Do you like Arrow?
✖