Hi there. I have a `Flow` emitting `1`, `2`, `3`. ...
# coroutines
u
Hi there. I have a
Flow
emitting
1
,
2
,
3
. Is there a way to transform this flow to emit:
[1]
,
[1,2]
,
[1,2,3]
. I know there’s this
fold
operator, but it’s terminal. In my case I need a value to be emitted on each accumulation step. Is there any appropriate operator out-of-the-box?
o
probably not out-of-the-box, as flow is designed to have minimal operators. you should build your own using
transform
scan
operator is close to what you want, but it would include an empty list due to its design
although I suppose you could
scan(...).skip(1)
z
Copy code
flow.scan(emptyList<Int>()) { list, value -> list + value }
    .drop(1)
👍 1
o
yes, that
u
thanks, guys!