title: What's the idiomatic Kotlin way to write `if...else null` as part of ?./?: chains?
body: <p>(Edited for clarity)</p>
  
  <p>I keep finding myself writing <code>(if (x) f() else null) ?: (if (y) g() else null) ?: (if (z) h() else null)</code> and similar and I'm sure I'm not the only oneץ</p>
  
  <p>I'm always reaching for a function like <code>valueIf</code> defined below (which is <code>takeIf</code> with order of parameters reversed so the value is lazy) , which would let me write code like <code>getViewEventType2()</code> instead of code like <code>getViewEventType1()</code> (both elaborated below).</p>
  
  <p>Is there an idiom I'm missing?</p>
  
  <p>(Also, is the compiler smart about functions like this, or should I fear creating too many temporary closures?)</p>
  
  <pre><code>    private fun getViewEventType1(): String? {
          return if (intent.action == "android.intent.action.VIEW") {
              intent.data?.pathSegments?.let {
                  if (it.size == 3 &amp;&amp; it[0] == "app" &amp;&amp; it[1] == "event") it[2]
                  else null
              }
          } else null
      }
  
      private fun getViewEventType2(): String? {
          return valueIf(intent.action == "android.intent.action.VIEW") {
              intent.data?.pathSegments?.let {
                  valueIf(it.size == 3 &amp;&amp; it[0] == "app" &amp;&amp; it[1] == "event") { it[2] }
              }
          }
      }
  
      inline fun &lt;T&gt; valueIf(condition: Boolean, func: () -&gt; T?) =
              if (condition) func() else null
  </code></pre>