Skip to content

Instantly share code, notes, and snippets.

@dwins
Created July 29, 2010 19:21
Show Gist options
  • Select an option

  • Save dwins/498972 to your computer and use it in GitHub Desktop.

Select an option

Save dwins/498972 to your computer and use it in GitHub Desktop.
def rle[A](as: Seq[A]): Seq[(Int, A)] = as match {
case Seq() => Seq()
case Seq(a, as @ _*) => (1 + as.takeWhile(a ==).length, a) +: rle(as.dropWhile(a ==))
}
rle("AAABBCCCDDDDE") map { case (i, c) => i.toString + c } mkString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment