Created
October 3, 2013 11:56
-
-
Save gbougeard/6808674 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| case class Page[A](items: Seq[A], page: Int, offset: Long, total: Long) { | |
| lazy val prev = Option(page - 1).filter(_ >= 0) | |
| lazy val next = Option(page + 1).filter(_ => (offset + items.size) < total) | |
| } | |
| object Page { | |
| implicit val writes: Writes[Page[A]] = ( | |
| (__ \ 'items).write[Seq[A]] ~ | |
| (__ \ 'page).write[Int] ~ | |
| (__ \ 'offset).write[Long] ~ | |
| (__ \ 'total).write[Long] | |
| ) (unlift(Page.unapply)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try