Last active
June 13, 2016 12:31
-
-
Save torholm/d8dcf8bd73330b6377b96bf52a0a156a 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
def paginate(min: Int, max: Int, selected: Int): String = { | |
require(selected <= max, "selected can't be bigger than max") | |
require(selected >= min, "selected can't be less than max") | |
require(max >= min, "max can't be bigger than min") | |
val winMax = Math.min(Math.max(min + 9, selected + 4), max) | |
val winMin = Math.max(Math.min(max - 8, selected - 5), min) | |
val prev = if (selected > min) "< " else "" | |
val next = if (selected < max) " >" else "" | |
val pages = (winMin to winMax).map { | |
case `selected` => "*" + selected + "*" | |
case x => x.toString | |
}.mkString(" " ) | |
prev + pages + next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment