Created
July 14, 2017 14:25
-
-
Save tnovoselec/73ba4946d4116e8f05946b5e40a3a031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Playground { | |
Observable<DiscussionPost> getPost(String commentId) { // this is your Api interface | |
return Observable.just(new DiscussionPost()); | |
} | |
Observable<List<DiscussionPost>> getPosts() { | |
return getPost("root").flatMap(new Func1<DiscussionPost, Observable<DiscussionPost>>() { | |
@Override | |
public Observable<DiscussionPost> call(DiscussionPost discussionPost) { | |
return Observable.from(discussionPost.posts); | |
} | |
}).flatMap(new Func1<DiscussionPost, Observable<DiscussionPost>>() { | |
@Override | |
public Observable<DiscussionPost> call(DiscussionPost discussionPost) { | |
return getPost(discussionPost.commentId); | |
} | |
}).toList(); | |
} | |
static class DiscussionPost { | |
String commentId; | |
List<DiscussionPost> posts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment