【发布时间】:2020-03-13 22:21:25
【问题描述】:
我有一个代表组中用户 ID 的 ID 列表的 Flowable。
private val memberIdsFlowable: Flowable<List<String>> = groupFlowable
.map { it.members }
我需要打电话
fun fetchUserFlowable(id: String): Flowable<User>
对于列表中的每个 id 并将它们组合成用户列表Flowable<List<User>>
我试过的是这样的:
private val membersFlowable = memberIdsFlowable
.concatMap { list ->
Flowable.fromIterable(list)
.map { userRepository.fetchUserFlowable(it) }
}
但它会导致Flowable<Flowable<User>> 而不是Flowable<List<User>>,如果我添加toList() 运算符,那么这是类型不匹配:
private val membersFlowable = memberIdsFlowable
.concatMap { list ->
Flowable.fromIterable(list)
.map { userRepository.fetchUserFlowable(it) }
.toList()
}
【问题讨论】:
标签: android kotlin rx-java rx-java2