Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created October 7, 2018 14:54
Show Gist options
  • Save Nublo/a30cd223a39d162f560fc662ed893e96 to your computer and use it in GitHub Desktop.
Save Nublo/a30cd223a39d162f560fc662ed893e96 to your computer and use it in GitHub Desktop.
fun <T> List<T>.filter(f: (T) -> Boolean): List<T> = when (this.size) {
0 -> listOf()
else -> if (f(head)) head + tail.filter(f) else tail.filter(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment