Is there a `collect` variant for `Flow` that allow...
# coroutines
l
Is there a
collect
variant for
Flow
that allows to access the previous value, or null for initial value?
g
you need something like
windowed
that will emit Pair(null, first) element
e
Not yet. Create an issue with your use-case please.
g
not sure that such operator exists
p
you need to combine with itself but skipping one value, it's a classic zipping structure
mergeAsTuple(flow, flow.skip(1)).map { (previous, current) -> ... }
dunno what are the API equivalents
@elizarov use case is any state machine that keeps track of transitions
j
that should really be something like
.publish { zip(flow, flow.skip(1), ::Pair) }
to avoid subscribing upstream twice
1
p
it'd work if
flow
there was
shared()
first too, right?
j
only if it's async so that's unsafe. if it's synchronous the entire stream will be consumed in the first subscription before
flow.skip(1)
is subscribed to yielding either two upstream subscriptions or no output
👍🏼 1
p
are we talking Rx or Kx?
...wait I may be thinking
cached()
for Rx
it's been a while
¯\_(ツ)_/¯
j
i'm sorta talking about both since they're really the same thing