image.png
# coroutines
j
image.png
I could implement this in a more beautiful way, but the StateFlowImpl class is private (I didn't understand why it is private)
g
It's private because it's implementation detail, you should use public builders, also you always can implement own with delegation
Your implementation is incorrect, it will not work, you never subscribe on state flow
Not quite sure what is your final goal with this (do you really need initial value or not (because every state already have default value. Looks that you just need:
Copy code
listSources.asFlow().flattenMerge().collect { doSomethingWiht(it) }
but maybe I misunderstood you case, becayse example above will cause inifinity cycle (on every event update you update it again which will cause one more update)
but your description “way to maintain multiple StateFlow related to an event? Reactive, to modifications to any of the states” is pretty clear and flattenMerge should work for it, but looks that you want modify it, which is not so clear for me
b
according to the first screenshot, combine + stateIn enough:
Copy code
val risk = combine(odd, bankMoney, comission, typeBet) { odd, money, comission, type -> 
    calcRisk(...)
}.stateIn(scope, 0)
j
@gildor, yeah hahah it didn't work as I expected, sorry, I just wanted to give you the idea of ​​what it would be like
@bezrukov I didn’t know this combine function with varargs, just the method inside Flow, Thanks, I imagine that’s the solution
@bezrukov "combine" do not respond with the "single ()" method, any solution?
g
why do you need single()?
could you show full example what you are trying to achieve
you can use https://play.kotlinlang.org/ to show example and demonstrate what doesn’t work for you
j
@gildor because i need get the value only once
g
yes, but what is not working? Maybe some of your flows in combine doesn’t emit first value