https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

myanmarking

08/20/2019, 9:42 AM
what's the idiomatic way of accomplish the same rx clickListener + textChangedListener, where the click triggers a save and the changedListener just validates some edittext. (clickListener.withLatestFrom(textChangedListener) ?
g

gildor

08/20/2019, 9:51 AM
Not sure about required semantics, but you always can propose to add operator
withLatestFrom
with your use case to kotlinx.coroutines issue tracker
m

myanmarking

08/20/2019, 9:52 AM
ya, i am asking because i didn't find any suitable approach to it. But maybe that's because i'm trying to find an rx replacement. if i think more imperativelly, i can just call a function when a click happens and have the problem solved
g

gildor

08/20/2019, 9:53 AM
no, I just think that such operator doesn’t exist, you can implement it tho
There is alredy PR with it
for now you can just copy implementation
m

myanmarking

08/20/2019, 9:55 AM
nice 😮 thanks
g

gildor

08/20/2019, 9:55 AM
still make sense to create a feature request
o

octylFractal

08/20/2019, 9:56 AM
a smaller but perhaps more expensive workaround I thought up:
Copy code
val clickFlow = ...
val textChangeFlow = ...
val resultFlow = clickFlow.zip(textChangeFlow).distinctUntilChangedBy { it.first }
basically, using the first flow to drive which values are considered part of the flow
👍 1
also requires that the first emits unique values, but for events I think that should suffice
2 Views