Reputation: 13
I'm working with RxJava, in Kotlin.
I have a function, transform(f: Foo): Single<Bar>
How can I take a List
of Foo
s, and perform transform
on each of them, to get a result of Flowable<Bar>
, where each next
in the Flowable
is the results of calling transform
?
Basically, I need a function
fun getFlowable(foos: List<Foo>): Flowable<Bar> {
// Runs transform() on each element of foos
// Concatenates the results to the flowable.
}
Upvotes: 0
Views: 173
Reputation: 3890
fun getFlowable(foos: List<Foo>, transform: (Foo) -> Bar): Flowable<Bar> =
Flowable.fromIterable(foos.map(transform))
or better version
fun getFlowable(foos: List<Foo>, transform: (Foo) -> Bar): Flowable<Bar> =
Flowable.fromIterable(foos).map(transform)
Upvotes: 1