https://kotlinlang.org logo
#stdlib
Title
# stdlib
m

mg6maciej

03/07/2018, 10:56 AM
Should I use
someMap.filterValues { it != null }.mapValues { it.value as Any }
or is there anything like
someList.filterNotNull()
for `Map`s?
i

ilya.gorbunov

03/07/2018, 12:19 PM
k

karelpeeters

03/07/2018, 12:46 PM
Is there no general solution coming for this? Ie. also for
.filter { it is String }
.
m

mg6maciej

03/07/2018, 12:48 PM
@karelpeeters
listOf<Any>().filterIsInstance<String>()
exists.
k

karelpeeters

03/07/2018, 12:52 PM
Hmm, okay. Still, I wonder if it is possible to get the typesystem to understand things like this?
i

ilya.gorbunov

03/07/2018, 1:30 PM
@karelpeeters It was a use case for contracts to express the relation between
filter
predicate and the return type, however we haven't yet found the way to express that (@dsavvinov correct me if I'm wrong)
k

karelpeeters

03/07/2018, 1:42 PM
That's unfortunate. I'm looking forward to the contract stuff though!
m

marcinmoskala

03/07/2018, 3:50 PM
You can make it yourself 😉