https://kotlinlang.org logo
#announcements
Title
# announcements
k

karelpeeters

08/21/2017, 11:45 AM
@arekolek There's this issue that's WIP, it's also about smart casts and inline functions: https://youtrack.jetbrains.com/issueMobile/KT-14397
👍 1
a

arekolek

08/21/2017, 11:52 AM
Thanks. I was thinking about things like
foo.takeIf { it is Foo }
for those cases where
foo
is a “property with an open or custom getter”
But I can write
foo.let { if (it is Foo) }
which is not too bad
l

lovis

08/21/2017, 12:17 PM
write your own:
inline fun <reified T> Any.takeIfInstance() = this.takeIf { it is T } as? T
should work call it
val astring = myObj.takeIfInstance<String>()
k

karelpeeters

08/21/2017, 12:18 PM
Hmm that rings a bell, doesn't something like that exists already?
Maybe for filtering collections.
l

lovis

08/21/2017, 12:18 PM
yes there is
filterIsInstance
and
mapIsInstance
(must have dreamt about the last one)
i

ilya.gorbunov

08/22/2017, 7:32 AM
just use
foo as? Foo
2 Views