我正在 Kotlin 中使用 RxJava。
我有一个功能, transform(f: Foo): Single<Bar>
我如何可以采取List
的Foo
s和执行transform
上的每个人,得到的结果Flowable<Bar>
,其中每个next
在Flowable
与调用的结果transform
?
基本上,我需要一个函数
fun getFlowable(foos: List<Foo>): Flowable<Bar> {
// Runs transform() on each element of foos
// Concatenates the results to the flowable.
}
fun getFlowable(foos: List<Foo>, transform: (Foo) -> Bar): Flowable<Bar> =
Flowable.fromIterable(foos.map(transform))
或更好的版本
fun getFlowable(foos: List<Foo>, transform: (Foo) -> Bar): Flowable<Bar> =
Flowable.fromIterable(foos).map(transform)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句