Skip to content

Instantly share code, notes, and snippets.

@christianb
Last active July 28, 2019 22:24
Show Gist options
  • Save christianb/ac0a40706e5db99f5372c26bac21d0b6 to your computer and use it in GitHub Desktop.
Save christianb/ac0a40706e5db99f5372c26bac21d0b6 to your computer and use it in GitHub Desktop.
Finds the generic type T in List
/**
* 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