Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. inline fun <reified T: Mammal> List<Mammal>.printAnimalResultsExtensionFiltered(
  2. factCheck: Mammal.() -> Int
  3. ): List<Mammal> {
  4. if (this.isNotEmpty()) {
  5. this.filterIsInstance<T>()
  6. .forEach {
  7. println("${it.javaClass.name} - ${it.factCheck()}")
  8. }
  9. }
  10. return this
  11. }
  12.  
  13. fun main() {
  14. println("\nSpecies count with list as param:")
  15. printAnimalResultFiltered<Sloth>(crewCrewCrew, Mammal::knownSpeciesCount)
  16. }
  17.  
  18. /** OUTPUT
  19. * Species count calculated in main:
  20. * Week3ReifiedGenerics.Sloth - 6
  21. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement