https://kotlinlang.org logo
#codereview
Title
# codereview
z

zmunm

04/06/2020, 5:45 AM
Is there simple function of this?
Copy code
list.lastOrNull { it is Goods } as? Goods
I just made this one
Copy code
inline fun <reified T> Collection<*>.findFirstInstance(): T? = firstOrNull { it is T } as? T

inline fun <reified T> Collection<*>.findLastInstance(): T? = lastOrNull { it is T } as? T
p

Paul Woitaschek

04/08/2020, 12:38 PM
Should be out T instead of star projection
Also as T?, not as? T
2 Views