Liking cljdoc? Tell your friends :D
Clojure only.

doccla.oth-client.pagination


paginate-resultsclj

(paginate-results f & [number-of-results])

Paginates through results by sequentially calling a provided function f with an increasing offset, to fetch a specified total number of results. The function f should accept an offset parameter and return a map with keys :response, containing a nested map with keys :total, :max, and :results.

The number-of-results parameter determines the total number of results to fetch. If it is not provided or if it is greater than the total number of available results, all results are fetched.

This function will handle the pagination logic by injecting the offset parameter to the provided function f, so it is necessary to provide an offset parameter to f and add it in the query parameters.

If one of the calls to f fails, the response of f will be returned immediately, without any further calls to f.

Usage example: (paginate-results (fn [offset] (get-audit-events oth-client {:event-name ["patient_updated"] :offset offset :max 10})) 100)

In this example, paginate-results is used to fetch 100 audit events, calling get-audit-events with batches of 10 results each time.

The return value will be in the same shape of the response of f, with the offset, max and links keys removed as they become irrelevant when the response has been accumulated, e.g. {:code 200 :success? true :response {:total 100 :results [{:some "data"} ...]}}

Paginates through results by sequentially calling a provided function `f` with an increasing offset,
to fetch a specified total number of results. The function `f` should accept an offset parameter and return
a map with keys `:response`, containing a nested map with keys `:total`, `:max`, and `:results`.

The `number-of-results` parameter determines the total number of results to fetch. If it is not provided or
if it is greater than the total number of available results, all results are fetched.

This function will handle the pagination logic by injecting the offset parameter to the provided function `f`,
so it is necessary to provide an offset parameter to `f` and add it in the query parameters.

If one of the calls to `f` fails, the response of `f` will be returned immediately, without any further calls to `f`.

Usage example:
(paginate-results
  (fn [offset]
    (get-audit-events oth-client {:event-name ["patient_updated"] :offset offset :max 10}))
  100)

In this example, `paginate-results` is used to fetch 100 audit events,
calling `get-audit-events` with batches of 10 results each time.

The return value will be in the same shape of the response of `f`,
with the offset, max and links keys removed as they become irrelevant when the response has been accumulated, e.g.
{:code     200
 :success? true
 :response {:total 100
            :results [{:some "data"} ...]}}
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close