https://kotlinlang.org logo
#flow
Title
# flow
c

Chris Fillmore

09/21/2021, 3:28 PM
Is there something like this
pipe
function (which I just made up) available in the coroutines library? (Sends emissions from one
Flow
to another
FlowCollector
) :
Copy code
suspend fun <T, U> Flow<T>.pipe(destination: FlowCollector<U>, transform: (T) -> U) {
  collect { 
    destination.emit(transform(it))
  }
}
It feels so obvious but I’ve been looking at the available extension functions and haven’t spotted it. Thanks!
d

diesieben07

09/21/2021, 3:31 PM
Isn't this just a combination of
emitAll
and
map
?
Copy code
destination.emitAll(
  source.map(transform)
)
c

Chris Fillmore

09/21/2021, 3:33 PM
Yes, you’re right.
I suppose I could just do that. Thanks for the tip!
2 Views