Higher-order functions in Kotlin

This post was originally posted at https://agrawalsuneet.github.io/blogs/higher-order-functions-in-kotlin/ and reposted on Medium on 7th Nov 2017.
fun <T> ArrayList<T>.filterOnCondition(condition: (T) -> Boolean): ArrayList<T>{
val result = arrayListOf<T>()
for (item in this){
if (condition(item)){
result.add(item)
}
}

return result
}

Please continue reading at https://agrawalsuneet.github.io/blogs/higher-order-functions-in-kotlin/

--

--

--

https://agrawalsuneet.github.io/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suneet Agrawal

Suneet Agrawal

https://agrawalsuneet.github.io/

More from Medium

Kotlin Programming Language: Everything You Need to Know

Kotlin Functions

Null Safety in Kotlin

Kotlin Collections & Operations