title: Kotlin when() local variable introduction
body: <p>Let's say I have an expensive function called <code>doHardThings()</code> which may return various different types, and I would like to take action based on the returned type. In Scala, this is a common use of the <code>match</code> construct:</p>
  
  <pre><code>def hardThings() = doHardThings() match {
       case a: OneResult =&gt; // Do stuff with a
       case b: OtherResult =&gt; // Do stuff with b
  }
  </code></pre>
  
  <p>I'm struggling to figure out how to do this cleanly in Kotlin without introducing a temporary variable for <code>doHardThings()</code>:</p>
  
  <pre><code>fun hardThings() = when(doHardThings()) {
       is OneResult -&gt; // Do stuff... with what?
       is OtherResult -&gt; // Etc...
  }
  </code></pre>
  
  <p>What is an idiomatic Kotlin pattern for this common use case?</p>