Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@lazyval /decode.scala secret
Last active

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
Something went wrong with that request. Please try again.