Skip to content

Instantly share code, notes, and snippets.

@TRBaldim
Created April 21, 2017 16:27
Show Gist options
  • Save TRBaldim/345af36976c73136ee377c6a81250b1d to your computer and use it in GitHub Desktop.
Save TRBaldim/345af36976c73136ee377c6a81250b1d to your computer and use it in GitHub Desktop.
Reverse a List in Scala
@tailrec
def reverseList[T](inputList: List[T], rList: List[T]): List[T] ={
inputList match {
case Nil => rList
case h::t => reverseList(t, h::rList)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment