Last active
July 28, 2019 22:24
-
-
Save christianb/ac0a40706e5db99f5372c26bac21d0b6 to your computer and use it in GitHub Desktop.
Finds the generic type T in List
This file contains hidden or 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
/** | |
* Finds the generic type T in List. | |
* | |
* @return first item that is instance of T or null. | |
*/ | |
inline fun <reified T> List<Any>.findType(): T? { | |
return find { it is T } as? T | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment