-
-
Save lazyval/bf0208414becf2e4e1ec to your computer and use it in GitHub Desktop.
quick code for http://stackoverflow.com/q/19645961/298389
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 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