Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 17 lines (14 sloc) 0.42 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// P11 Modified run-length encoding.

// List of objects
def f1[T](list: List[(Int, T)]): List[Any] = list.map {
  case (1, x) => x
  case it => it
}

// With custom data
abstract sealed class Entry[T]
case class Value[T](v: T) extends Entry[T]
case class Sequence[T](n: Int, v: T) extends Entry[T]

def f2[T](list: List[(Int, T)]): List[Entry[T]] = list.map {
  case (1, x) => Value(x)
  case (n, x) => Sequence(n, x)
}
Something went wrong with that request. Please try again.