Last active
December 11, 2015 18:28
-
-
Save vkostyukov/4641224 to your computer and use it in GitHub Desktop.
True version of "reverse list problem" in Scala
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
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