Advertisement
Guest User

Untitled

a guest
Aug 9th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. @Test
  2. public void test() {
  3. getBooks()
  4. .flatMapSingle(bookList -> Flowable.fromIterable(bookList)
  5. .flatMap(book -> getCategories(book.id)
  6. .map(categories -> {
  7. book.categories = categories;
  8. return book;
  9. }))
  10. .flatMap(book -> getAuthors(book.id)
  11. .map(authors -> {
  12. book.authors = authors;
  13. return book;
  14. }))
  15. .toList())
  16. .subscribe(bookList -> {
  17. //done
  18. });
  19. }
  20.  
  21. Flowable<List<Book>> getBooks() {
  22. return Flowable.just(Arrays.asList(new Book(), new Book()));
  23. }
  24.  
  25. Flowable<List<Category>> getCategories(int id) {
  26. return Flowable.just(Arrays.asList(new Category(), new Category()));
  27. }
  28.  
  29. Flowable<List<Author>> getAuthors(int id) {
  30. return Flowable.just(Arrays.asList(new Author(), new Author()));
  31. }
  32.  
  33. static class Book {
  34. int id = 0;
  35. public List<Author> authors;
  36. public List<Category> categories;
  37. }
  38.  
  39. static class Author {}
  40.  
  41. static class Category {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement