So you can update your article to mention `listOf(...
# announcements
o
So you can update your article to mention
listOf(1, “2”, 3).filterIsInstance<String>().first()
which gives you
String
value
👍 1
d
orangy: how about first/firstOrNull ?
o
Anything wrong about them? 🙂
d
nothing but is there easy way to find first and cast?
b
Post updated, but I still would love smart cast throughout the language 😎
o
Smart casts are everywhere, where it is possible for compiler to infer them. In an arbitrary function receiving a lambda it cannot deduce it. Well, it could in some cases, if it could see through inline lambda, but not for collections.
b
Yeah but you can still dream 😃 Btw awesome response here! Love it! Is there anywhere a kotlin-developer like myself can contribute to the language or community? Where would you recommend that to be?
o
You might want to ask in #kontributors
b
Cool, I’ll do that. I also first solved my problem with Rx with an extension function in kotlin combining
filter
and
map
. And than I found that Rx actually has a filter function for it as well:
ofType
This was my extension solution:
Copy code
fun <T,U:T> Observable<T>.filterMap( cls:Class<U> ):Observable<U> { 
  return filter { cls.isInstance( it ) }
           .map { cls.cast( it ) }
}