title: How can I check if a set of functions all return non null, in a single expression?
body: <p>Suppose I have three functions <code>foo</code>, <code>bar</code>, <code>baz</code>, all of which return nullable types.</p>
  <pre><code>fun foo(): Int? = 1
  fun bar(): Int? = 2
  fun baz(): Int? = 3
  </code></pre>
  <p>I want to call them, and if all them returns non-null, I want to compute a value from their return values.</p>
  <p>I could do this with <em>statements</em>, like this:</p>
  <pre><code>val x = foo()
  val y = bar()
  val z = baz()
  val result = if (x != null &amp;&amp; y != null &amp;&amp; z != null) x + y + z else null
  </code></pre>
  <p>However, I don't like the fact that I have to declare 3 extra variables that I can still access afterwards. By having 3 extra statements like this, it also means that I cannot use expression-bodied functions, if I were writing a function that returns <code>result</code>.</p>
  <p>If I use <code>let</code>s instead:</p>
  <pre><code>val result = foo()?.let { x -&gt; 
      bar()?.let { y -&gt; 
          baz()?.let { z -&gt; 
              x + y + z
          } 
      } 
  }
  </code></pre>
  <p>This creates a deep nesting. If it were only one function, this would have been fine, but with 3 functions or more, this makes my intention of &quot;call these three functions, if they are all non null, add them together&quot; rather unclear.</p>
  <p>How can I write this in a way that clearly conveys my intention, but also making it a single expression?</p>