Skip to content

Instantly share code, notes, and snippets.

@lazyval
Last active December 26, 2015 20:08
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 lazyval/bf0208414becf2e4e1ec to your computer and use it in GitHub Desktop.
Save lazyval/bf0208414becf2e4e1ec to your computer and use it in GitHub Desktop.
def decode[A](xs: List[(Int, A)]) : Seq[A] = xs match {
case Nil => Nil
case (times, code) :: xs => (for (i <- 1 to times) yield code) ::: decode(xs)
}
// you may also replace
// (for (i <- 1 to times) yield code)
// with
// Seq.fill(3)(code)
// so you will get
// case (times, code) :: xs => Seq.fill(times)(code) ::: decode(xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment