arrow-fx-coroutines / arrow.fx.coroutines.stream / repartition

repartition

fun <O> Stream<O>.repartition(S: Semigroup<O>, f: (O) -> Chunk<O>): Stream<O>

Repartitions the input with the function f. On each step f is applied to the input and all elements but the last of the resulting sequence are emitted. The last element is then appended to the next input using the Semigroup S.

import arrow.fx.coroutines.stream.*
import arrow.core.extensions.semigroup

//sampleStart
suspend fun main(): Unit =
  Stream("Hel", "l", "o Wor", "ld")
    .repartition(String.semigroup()) { s -> Chunk.iterable(s.split(" ")) }
    .toList()
    .let(::println) //[Hello, World]
//sampleEnd

Do you like Arrow?

Arrow Org
<