I have a list List<FileModel>
FileModel
is just a class contains id: Int
id
- is ID of photo file I need to fetch and cast to Bitmap
I have a request:
fun getFile(fileId: Int): Single<ResponseBody>
This request returns ResponseBody
which we can cast to Bitmap
And
fun generatePhoto(responseBody: ResponseBody): Single<Bitmap?>
What I want is to create a function
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
}
I've tried something like this but it's completely wrong
fun getPhotos(list: List<FileModel>): Single<List<Bitmap>> {
return Observable.fromIterable(list)
.flatMap { getFile(it.id) }
// How to call generatePhoto(...) here?
}