【发布时间】:2018-10-21 22:41:21
【问题描述】:
我有一个列表List<FileModel>
FileModel 只是一个包含id: Int 的类
id - 是我需要获取并投射到位图的照片文件的 ID
我有一个请求:
fun getFile(fileId: Int): Single<ResponseBody>
此请求返回ResponseBody,我们可以将其转换为位图
和
fun generatePhoto(responseBody: ResponseBody): Single<Bitmap?>
我想要的是创建一个函数
fun getPhotos(list: List<FileModel>): Single<List<Bitmap>> {
// Execute getFile(...) for each item in the list
// Cast getFile(...) result to Bitmap using generatePhoto(...)
// Return a list of Bitmaps
}
我尝试过类似的方法,但完全错误
fun getPhotos(list: List<FileModel>): Single<List<Bitmap>> {
return Observable.fromIterable(list)
.flatMap { getFile(it.id) }
// How to call generatePhoto(...) here?
}
【问题讨论】:
-
我不是 Rx 专家,你能举个例子吗?
-
其实应该就是flatMap吧。
标签: android kotlin rx-java2 rx-android rx-kotlin