Skip to content

Instantly share code, notes, and snippets.

@jtrupiano
Created April 21, 2009 00:16
Show Gist options
  • Save jtrupiano/98856 to your computer and use it in GitHub Desktop.
Save jtrupiano/98856 to your computer and use it in GitHub Desktop.
def flatten(lst: List[Any]): List[Any] = {
lst match {
case Nil => List[Any]()
case (head:List[Any]) :: body => flatten(head) ::: flatten(body)
case head :: body => head :: flatten(body)
}
}
flatten(List(List(1, 1), 2, List(3, List(5, 8))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment