Handle Paging with RxJava

You could model it recursively: Observable<ApiResponse> getPageAndNext(int page) { return getResults(page) .concatMap(new Func1<ApiResponse, Observable<ApiResponse>>() { @Override public Observable<ApiResponse> call(ApiResponse response) { // Terminal case. if (response.next == null) { return Observable.just(response); } return Observable.just(response) .concatWith(getPageAndNext(response.next)); } }); } Then, to consume it, getPageAndNext(0) .concatMap(new Func1<ApiResponse, Observable<ResponseObject>>() { @Override public Observable<ResponseObject> call(ApiResponse response) { return Observable.from(response.results); … Read more

Pagination in CouchDB?

The CouchDB Guide has a good discussion of pagination, including lots of sample code, here: http://guide.couchdb.org/draft/recipes.html#pagination Here’s their algorithm: Request rows_per_page + 1 rows from the view Display rows_per_page rows, store last row as next_startkey As page information, keep startkey and next_startkey Use the next_* values to create the next link, and use the others … Read more

How to paginate associated records?

The paginator doesn’t support paginating associations, you’ll have to read the associated records manually in a separate query, and paginate that one, something along the lines of this: $product = $this->Products ->findBySlug($slug_prod) ->contain([‘Metas’, ‘Attachments’]) ->first(); $categoriesQuery = $this->Products->Categories ->find() ->innerJoinWith(‘Products’, function (\Cake\ORM\Query $query) use ($product) { return $query->where([ ‘Products.id’ => $product->id, ]); }) ->group(‘Categories.id’); $paginationOptions … Read more

Paginate Observable results without recursion – RxJava

JohnWowUs’ answer is great and helped me understand how to avoid the recursion effectively, but there were some points I was still confused about, so I’m posting my tweaked version. Summary: The individual pages are returned as a Single. Use a Flowable to stream each of the items contained in the pages. This means callers … Read more

PHP/MySQL Pagination

SELECT col FROM table LIMIT 0,5; — First page, rows 1-5 SELECT col FROM table LIMIT 5,5; — Second page, rows 6-10 SELECT col FROM table LIMIT 10,5; — Third page, rows 11-15 Read the LIMIT section on the MySQL SELECT helppage. If you want to display the total number of rows available, you can … Read more

How can I paginate a merged collection in Laravel 5?

however paginate is for eloquent models and DB queries, and not collections, it seems. You are right. but there is ineed a paginator function for collections. forPage Syntax: Collection forPage(int $page, int $perPage) Example: Rest is simple. public function foo() { $collection = collect([1,2,3,4,5,6,7,8,9,0]); $items = $collection->forPage($_GET[‘page’], 5); //Filter the page var dd($items); }

tech