Skip to content

Instantly share code, notes, and snippets.

@ramannanda9
Last active July 31, 2017 19:51
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 ramannanda9/d1bbd3cb7ab05957ee28af840ac2b8fe to your computer and use it in GitHub Desktop.
Save ramannanda9/d1bbd3cb7ab05957ee28af840ac2b8fe to your computer and use it in GitHub Desktop.
filter in scala
def filter[K](arr: List[K], f: K => Boolean): List[K] = arr match {
case Nil => arr
case list: List[K] => if (f(list.head)) list.head :: filter(list.tail, f) else filter(list.tail, f)
}
val listToFilter = 2 :: 5 :: Nil
listToFilter.filter(_ > 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment