Created
June 1, 2018 22:18
-
-
Save danielbraun/8a4272418ad7b6be87ee0cef8c1f771c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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