https://kotlinlang.org logo
#android
Title
# android
l

leolima

10/22/2018, 12:07 PM
something like
fetchAlbums().flatMap { album -> fetchPhotos(album.id).map { photos -> album to photos } }
would give you a pair of album / photos
s

Soundlicious

10/22/2018, 2:01 PM
it's a pair, not a list of pair 😕 I can't find how to get a list from there... apparently i can't use flatmap(listOf(it)) on the result of my map nor on the first flatmap. I'll continue that after dinner
l

leolima

10/22/2018, 4:18 PM
oh, i see. maybe:
Copy code
fetchAlbums()
      .flatMapObservable { fromIterable(it) }
      .flatMap { album -> 
        fetchPhotos(album.id)
            .toObservable()
            .map { photos -> album to photos} 
      }
      .toList()
s

Soundlicious

10/23/2018, 3:11 AM
i don't have flatMapObservable. I already did something like that in java, didn't took me that long to figure out how to do it >.< I missing something here but don't know what ...
ah i found my old project, i wasn't keeping the reference from the first request, i was just using it to get all the final request.
fixed it : userService.fetchUserAlbums(state.id) .flatMap { album -> userService.fetchUserPhotos(album.id) .map { photo -> listOf(photo) } .map { listOf(PhotoAlbumModel(album, photos = it)) } }.execute { copy(id = state.id, request = it) }
@leolima Thanks a lot for putting me on the good track 👍