Uziel Sulkies
09/18/2019, 7:14 PMShawn
09/18/2019, 7:16 PMfilterNot will do what you want it toShawn
09/18/2019, 7:16 PMShawn
09/18/2019, 7:16 PMV as V : Anystreetsofboston
09/18/2019, 7:16 PMthis.filterNot { it.value == null }.map { it as Entry<K,V> } (not sure if Entry is the correct name)streetsofboston
09/18/2019, 7:17 PMstreetsofboston
09/18/2019, 7:18 PMthis.filterNot { it.value == null } as Map<K,V>Kroppeb
09/18/2019, 7:20 PMUziel Sulkies
09/18/2019, 7:23 PMstreetsofboston
09/18/2019, 7:25 PMfun <K, V : Any> Map<K,V?>.filterNotNull(): Map<K,V> =
filter { it.value != null } as Map<K,V>Shawn A
09/18/2019, 7:40 PMShawn
09/18/2019, 7:43 PMmapNotNullShawn
09/18/2019, 7:43 PMShawn
09/18/2019, 7:43 PMfun <K : Any, V : Any> Map<K, V?>.filterNullValues(): Map<K, V> {
return mapNotNull { it.value?.let { value -> it.key to value } }.toMap()
}Shawn
09/18/2019, 7:43 PMmapNotNull returns List<R>Shawn
09/18/2019, 7:43 PMMap<K, V>Shawn A
09/18/2019, 7:47 PMShawn
09/18/2019, 7:48 PMmapNotNull route involves different tradeoffs, mostly just more iteration over your collection