Skip to content

Instantly share code, notes, and snippets.

@clojj
Forked from jacquesgiraudel/FindByTitleKotlin.kt
Created October 16, 2018 19:49
Show Gist options
  • Save clojj/525ecf54d1de938840909c94cc2899e5 to your computer and use it in GitHub Desktop.
Save clojj/525ecf54d1de938840909c94cc2899e5 to your computer and use it in GitHub Desktop.
var findByTitle: (String) -> (MutableList<Movie>) -> List<Movie> =
{ query -> { collection ->
val predicate = matches(query)
filter(predicate)(collection)
}}
val filter: ((Movie) -> Boolean) -> (List<Movie>) -> List<Movie> =
{ predicate -> { collection ->
collection.filter(predicate)
}}
val matches: (String) -> (Movie) -> Boolean =
{ query -> { movie ->
isInfixOf(query) (title(movie))
}}
val title: (Movie) -> String =
{ movie -> movie.title}
val isInfixOf: (String) -> (String) -> Boolean =
{ query -> { string ->
string.contains(query)
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment