Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline fun <reified T: Mammal> List<Mammal>.printAnimalResultsExtensionFiltered(
- factCheck: Mammal.() -> Int
- ): List<Mammal> {
- if (this.isNotEmpty()) {
- this.filterIsInstance<T>()
- .forEach {
- println("${it.javaClass.name} - ${it.factCheck()}")
- }
- }
- return this
- }
- fun main() {
- println("\nSpecies count with list as param:")
- printAnimalResultFiltered<Sloth>(crewCrewCrew, Mammal::knownSpeciesCount)
- }
- /** OUTPUT
- * Species count calculated in main:
- * Week3ReifiedGenerics.Sloth - 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement