Learn to Code ยท zero-dependency ยท MIT

larzpaginate

Pagination done right.

Every app that shows a list needs to break it into pages, and the arithmetic (which slice, how many pages, is there a next, 'showing 21-30 of 57') is fiddly and easy to get wrong. larzpaginate does it once, correctly, returning a Page with the slice and every number you need.

larzscript pkg install paginate
View on GitHub →Learn the stack

What you get

Try it

import "paginate" as paginate
let items = ["a","b","c","d","e","f","g","h","i","j","k","l"]
let p = paginate.paginate(items, 2, 5)
print(p["items"])
print("page", p["page"], "of", p["pages"], "- has_next:", p["has_next"], "has_prev:", p["has_prev"])
Output
[f, g, h, i, j]
page 2 of 3 - has_next: true has_prev: true

Why it's in the Larz Stack

larzpaginate is a real Larzscript package (larzscript pkg install paginate) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.