0

I have 2 api methods.

@POST("/api/photos/")
Single<List<Photo>> getPhotos();

@POST("/api/user/profile")
Single<Profile> getProfile(@Query("photoId") String photoId);

I want to return Single < List < Pair < Photo,Profile>>> after combining some rx operations and this api methods. Is it possible? How?

1 Answer 1

2

This is my solution

public class TestCombining {
    public Single<List<Pair<Photo, Profile>>> test(ApiInterface apiInterface) {
        return apiInterface.getPhotos()
                .flattenAsObservable(photos -> photos)
                .flatMap(photo -> apiInterface.getProfile(photo.getId())
                        .map(profile -> new Pair<>(photo, profile)).toObservable())
                .toList();
    }

    interface ApiInterface {
        Single<List<Photo>> getPhotos();

        Single<Profile> getProfile(String photoId);
    }

    interface Profile {
        String getPhotoId();
    }

    interface Photo {
        String getId();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.