Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tpolecat
Created December 8, 2014 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpolecat/599627eac471b36f9a2a to your computer and use it in GitHub Desktop.
Save tpolecat/599627eac471b36f9a2a to your computer and use it in GitHub Desktop.
def mergeRanges(ns: List[Int]): List[Range] =
ns.foldRight(List.empty[Range]) {
case (n, r :: rs) if (n == r.min - 1) => (n to r.max) :: rs
case (n, rs) => (n to n) :: rs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment