Skip to content

Instantly share code, notes, and snippets.

@danielbraun
Created June 1, 2018 22:18
Show Gist options
  • Save danielbraun/8a4272418ad7b6be87ee0cef8c1f771c to your computer and use it in GitHub Desktop.
Save danielbraun/8a4272418ad7b6be87ee0cef8c1f771c to your computer and use it in GitHub Desktop.
(defn paginate
([coll] (paginate 1 coll))
([n coll] (paginate 25 n coll))
([per-page n coll]
(let [partitioned (vec (partition-all per-page coll))
page (or n 1)]
(some-> (get partitioned (dec page))
(with-meta (let [page-count (count partitioned)]
#:pagination{:total-count (count coll)
:page-count page-count
:has-next? (< page page-count)
:has-previous? (> page 1)
:current-page page}))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment