Skip to content

Instantly share code, notes, and snippets.

@JorgeCastilloPrz
Last active May 5, 2017 22:14
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 JorgeCastilloPrz/be8322da0ebc74c90c86305b043bf6d1 to your computer and use it in GitHub Desktop.
Save JorgeCastilloPrz/be8322da0ebc74c90c86305b043bf6d1 to your computer and use it in GitHub Desktop.
tail rec filter for blog post
fun <T> filter(l: List<T>, res: List<T>, f: (T) -> Boolean): List<T> {
if (l.isEmpty()) {
return res
} else {
return filter(l.tail(), if (f(l.head())) { res + listOf(l.head())} else { res }, f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment