Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void test() {
- getBooks()
- .flatMapSingle(bookList -> Flowable.fromIterable(bookList)
- .flatMap(book -> getCategories(book.id)
- .map(categories -> {
- book.categories = categories;
- return book;
- }))
- .flatMap(book -> getAuthors(book.id)
- .map(authors -> {
- book.authors = authors;
- return book;
- }))
- .toList())
- .subscribe(bookList -> {
- //done
- });
- }
- Flowable<List<Book>> getBooks() {
- return Flowable.just(Arrays.asList(new Book(), new Book()));
- }
- Flowable<List<Category>> getCategories(int id) {
- return Flowable.just(Arrays.asList(new Category(), new Category()));
- }
- Flowable<List<Author>> getAuthors(int id) {
- return Flowable.just(Arrays.asList(new Author(), new Author()));
- }
- static class Book {
- int id = 0;
- public List<Author> authors;
- public List<Category> categories;
- }
- static class Author {}
- static class Category {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement