title: Filter null keys and values from map in Kotlin
body: <p>I have an extension function that filters away entries with null keys or values:</p>
  
  <pre><code>fun &lt;K, V&gt; Map&lt;K?, V?&gt;.filterNotNull(): Map&lt;K, V&gt; = this.mapNotNull { 
     it.key?.let { key -&gt; 
        it.value?.let { value -&gt; 
           key to value 
        }
     }
  }.toMap()
  </code></pre>
  
  <p>This works for a map with nullable keys and values:</p>
  
  <pre><code>data class Stuff(val foo: Int)
  
  val nullMap = mapOf&lt;String?, Stuff?&gt;(null to (Stuff(1)), "b" to null, "c" to Stuff(3))
  assert(nullMap.filterNotNull().map { it.value.foo } == listOf(3))
  </code></pre>
  
  <p>But not in one that has non-nullable keys or values:</p>
  
  <pre><code>val nullValues = mapOf&lt;String, Stuff?&gt;("a" to null, "b" to Stuff(3))    
  assert(nullValues.filterNotNull().map { it.value.foo } == listOf(3))
  
  Type mismatch: inferred type is Map&lt;String, Stuff?&gt; but Map&lt;String?, Stuff?&gt; was expected
  Type inference failed. Please try to specify type arguments explicitly.
  </code></pre>
  
  <p>Is there a way to make my extension function work for both cases, or do I need to provide two separate functions?</p>