title: Linq TypeScript Ternary Operator - is it possible to re-use the condition as the first expression without duplicating code?
body: <p>My question is pretty simple and I've searched through StackOverflow, StackExchange + some other sites trying to find an answer, but have come up a little short. </p>
  
  <p>It's regarding a Linq ternary expression, i.e.</p>
  
  <pre><code>Condition ? Expression1 : Expression2;
  </code></pre>
  
  <p>Essentially, can I re-use the <code>Condition</code> of a Linq ternary expression as the first returned <code>Expression</code>? Is this possible?</p>
  
  <p>The reason for me wanting to do this is I have a very long Linq ternary expression which spans 3 lines in-code and extends over 183 characters. The main reason it is so long is because of some strings &amp; variable names.</p>
  
  <p><strong>An abridged version of my code is as follows:</strong></p>
  
  <pre><code>var x = array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME") ? array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME") : null;
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>var x = array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME") ? array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME").value : null;
  </code></pre>
  
  <p>A couple of solution's I've considered are:</p>
  
  <ul>
  <li>Store the <code>array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME")</code> section in a variable to reference later</li>
  <li>Use an <code>If</code> statement</li>
  </ul>
  
  <p>I have decided against both of these as they add additional overhead in terms of how much physical code is on the page. </p>
  
  <p>I guess what it boils down to is, does something like this exist? (Where <code>this</code> is the initial condition)</p>
  
  <pre><code>var x = array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME") ? this : null;
  </code></pre>
  
  <p>It may also be used in this context where I'm after a specific value stored in the object:</p>
  
  <pre><code>var x = array.find(x =&gt; x.key == "EXAMPLE_KEY_NAME") ? this.value : null;
  </code></pre>
  
  <p>This is my first time asking a question though I've answered quite a few questions, so please feel free to give constructive feedback or point me in the direction of documentation to read!</p>