Skip to content

Instantly share code, notes, and snippets.

@vkostyukov
Last active December 11, 2015 18:28
Show Gist options
  • Save vkostyukov/4641224 to your computer and use it in GitHub Desktop.
Save vkostyukov/4641224 to your computer and use it in GitHub Desktop.
True version of "reverse list problem" in Scala
object Reverse extends App {
def reverse(l: List[Int]): List[Int] = l match {
case head :: Nil => head :: Nil
case head :: tail => reverse(tail) :+ head
}
assert { reverse(List(1, 2, 3, 4, 5)).corresponds(List(5, 4, 3, 2, 1)) {_ == _} }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment