Hello everyone. Is there a alternative to `Observa...
# coroutines
s
Hello everyone. Is there a alternative to
ObservableTransformer
when using
Flow
or
Channel
?
p
An extension function
s
For Flows, transformers, or just custom operators, look more or less like this:
Copy code
fun <T> Flow<T>.myTransformer(...) = flow {
    ...
        this.collect {
            ...
            ... do your stuff whatever it is ...
                emit(it)
            ...
        }
    ...
}
You can add loops, flow control, etc, whatever you want
p
That's a different concept. An ObservableTransformer is more like an extension function @streetsofboston
s
The example I gave is an extension function. And Rx Transformers can be used to create your own custom Rx operators. And my example is a custom operator on a Flow.
p
Hm Imo a observable transformer just lets you combine existing operators
s
You can just combine other operators in the
apply
of the Transformer, like you said, but you can do a lot more funky stuff as well. 🙂
s
Oh yeah, this makes a lot of sense. I was trying to find a 1:1 replacement for
ObservableTransformer
. Thanks 👍🏽
My use case was mainly implementing the transformer as a interface for a object/class. But extension functions also works I think.