https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Alderson Elliot

02/20/2022, 8:34 AM
Kotlin Flow have pipe like rxjs sample? https://rxjs.dev/api/operators/sample
s

Sam

02/20/2022, 8:40 AM
As far as I understand it,
pipe
is used to avoid nesting lots of operators. Kotlin uses extension functions for Flow operators, which solves the same problem, so there's no need for a
pipe
equivalent.
By nested operators, I mean something like the example in the docs you linked to:
Copy code
op4()(op3()(op2()(op1()(obs))))
In Kotlin, it would be more like
Copy code
flow.op1().op2().op3().op4()
a

Alderson Elliot

02/20/2022, 8:43 AM
sorry, I don’t have a problem with the extended way of writing Flow. I want to achieve the effect of the rxjs
sample
in kotlin Flow
s

Sam

02/20/2022, 8:44 AM
Oh I see, you were asking about sample rather than pipe
I misunderstood your question!
a

Alderson Elliot

02/20/2022, 8:44 AM
Sorry, my native language is not English😣
s

Sam

02/20/2022, 8:46 AM
I think you could achieve the behaviour of
sample
by using
combine
or maybe
combineLatest
a

Alderson Elliot

02/20/2022, 8:47 AM
Flow also has the sample method, but it doesn’t seem to be the same as the sample operator in rxjs
👍 1
two flow with one list solved😄
2 Views