coinglecko/pagination
Pagination helpers for endpoints that return paged results.
Types
Parameters for paginated requests.
pub type PageParams {
PageParams(page: Int, per_page: Int)
}
Constructors
-
PageParams(page: Int, per_page: Int)
A paged response wrapping the data with pagination metadata.
pub type PagedResponse(a) {
PagedResponse(
data: List(a),
page: Int,
per_page: Int,
has_more: Bool,
)
}
Constructors
-
PagedResponse( data: List(a), page: Int, per_page: Int, has_more: Bool, )
Values
pub fn collect_all(
fetch_page fetch: fn(PageParams) -> Result(List(a), e),
from params: PageParams,
) -> Result(List(a), e)
Collect all pages by repeatedly calling a fetch function. Stops when a page returns fewer items than per_page.
pub fn collect_each(
fetch_page fetch: fn(PageParams) -> Result(List(a), e),
from params: PageParams,
with callback: fn(List(a), PageParams) -> Result(Nil, e),
) -> Result(Nil, e)
Process pages one at a time via a callback, without accumulating all data. Useful for large datasets where you want to process each page independently.
pub fn default_params() -> PageParams
Create default page params (page 1, 100 per page).
pub fn has_more(results: List(a), per_page: Int) -> Bool
Determine if there are likely more results based on the result count.
pub fn to_paged_response(
data: List(a),
params: PageParams,
) -> PagedResponse(a)
Build a PagedResponse from a list of results and page params.