https://kotlinlang.org logo
Title
a

Alexander Maryanovsky

05/23/2022, 8:42 AM
Why does
combine(flows, transform)
not call
transform
if
flows
is empty? Is that intended? Seems like it would be more natural to call it with an empty array.
e

ephemient

05/23/2022, 11:27 AM
I don't think so. the transform should only be called when there are emissions, and there are none here
a

Alexander Maryanovsky

05/23/2022, 11:36 AM
My use-case is that I have a list of flows of
Int
, and I need to return a flow of their sum.
combine(flows, Array<Int>::sum)
seems like an intuitive solution that fails when
flows
is empty.
e

ephemient

05/23/2022, 11:55 AM
combine(List(n) { flowOf(*Array(m) { 0 }) }, transform)
the way I see it: in general, this can call
transform
anywhere in
n..n*(m-1)+1
times. when
n=0
, 0 times is a reasonable ourcome
a

Alexander Maryanovsky

05/23/2022, 12:20 PM
On the other hand
combine(List(n){ flowOf(0) }, transform)
calls transform exactly once for every value of
n
except
0
n

Nick Allen

05/23/2022, 5:50 PM
combine(List(n){ flowOf(0) }, transform)
also receives emitted most recent values (which is what it operates on) for every
n
except
0
.
e

ephemient

05/23/2022, 5:54 PM
combine(List(n) { flowOf() }, transform)
calls
transform
0 times for any value of
n
, including 0