Last active
May 5, 2017 22:14
-
-
Save JorgeCastilloPrz/be8322da0ebc74c90c86305b043bf6d1 to your computer and use it in GitHub Desktop.
tail rec filter for blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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