Skip to content

Instantly share code, notes, and snippets.

@fahadsiddiqui
Created April 27, 2017 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahadsiddiqui/aa596d917cb3ecf9632069b19134dc82 to your computer and use it in GitHub Desktop.
Save fahadsiddiqui/aa596d917cb3ecf9632069b19134dc82 to your computer and use it in GitHub Desktop.
def foo(l: List[Any]): List[Int] = {
l flatMap {
case e: Int => List(e)
case f: List[Any] => foo(f)
}
}
foo(List(1, List(1, 3, List(1, 7, List(3, 5, 7))))) // results List(1, 1, 3, 1, 7, 3, 5, 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment