title: Kotlin smart cast the second value of a pair with filter
body: <p>I'm trying to write a function that maps a String and Int? into a pair, then filters for non null second values in the pair, before continuing to map.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>val ids: List&lt;String&gt; = listOf("a", "b", "c")
  val ints: Map&lt;String, Int?&gt; = mapOf("a" to 1, "b" to 2, "c" to null)
  
  ids.map { id: String -&gt;
      Pair(id, ints[id])
  }.filter { pair -&gt; pair.second != null}.map { pair: Pair&lt;String, Int&gt; -&gt;
      func(id, pair.second)  
  }
  </code></pre>
  
  <p>The problem is that the second map has the error: </p>
  
  <pre><code>Type inference failed: Cannot infer type parameter T in 
                         inline fun &lt;T, R&gt; kotlin.collections.Iterable&lt;T&gt;.map ( transform (T) -&gt; R ): kotlin.collections.List&lt;R&gt;
  </code></pre>
  
  <p>This looks like because the compiler does not know to smart cast my <code>Iterable&lt;Pair&lt;String, Int?&gt;&gt;</code> into an <code>Iterable&lt;Pair&lt;String, Int&gt;&gt;</code> after my <code>filter</code>. What can I do instead to solve this?</p>