Flow to variable length chunks

I’ve got two flows:

  1. bigThings:Flow<LargeObject> = ....
  2. counts:Flow<Int> = (1..3).asFlow()

Is there a way to transform them into variable length “chunks”, where the chunk-size is determined by the counts? like a bigThings.combineBy(counts)

output: Flow<Flow<LargeObject>>
where the first entry from the flow is a flow of 1 object, the second is a flow of 2, and the third has 3.

It feels like it might be “wrong” - like the chunking step would have to vary as it goes, which might (?) violate the flow philosophy?

1 Like

As far as I know there isn’t any function that can do this atm. There was a discussion about this here with a possible implementation but it wasn’t implemented so far because the kotlinx.coroutine team wasn’t sure about the final design of it.

1 Like