Skip to content

Instantly share code, notes, and snippets.

@siejkowski
Last active December 24, 2015 12:29
Show Gist options
  • Save siejkowski/6797685 to your computer and use it in GitHub Desktop.
Save siejkowski/6797685 to your computer and use it in GitHub Desktop.
def encodeModified(list: List[Symbol]) : List[Any] = {
list.foldRight(List[Any]()) {
(h, l) =>
if (l.isEmpty)
List(h)
else
l.head match {
case (x: Int, y) =>
if (y == h)
(x + 1, y) :: l.tail
else
h :: l
case e =>
if (e == h)
(2,h) :: l.tail
else
h :: l
}
}
}
encodeModified(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment