Last active
August 7, 2018 09:28
-
-
Save delabassee/f14a79d5fe2fef34f04c24dbe5315828 to your computer and use it in GitHub Desktop.
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
import com.delabassee.Country | |
fun country(input: String): List<Country> = when { | |
input.isEmpty() -> Country.getAll() | |
else -> Country.getAll().filteredOrAll { | |
it.name.contains(input.trim(), true) | |
} | |
} | |
private fun <T> List<T>.filteredOrAll(predicate: (T) -> Boolean): List<T> { | |
val filtered = filter(predicate) | |
return when { | |
filtered.isEmpty() -> this | |
else -> filtered | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/fnproject/kotlin-and-the-java-fdk-ffcf1778c74a