title: Is there a java lambda expression equivalent of the C# linq let?
body: <p>Is there a java 8 lambda expression equivalent of the let setting? For instance, how would I write this c# linq expression using Java 8 lambda expressions?</p>
  
  <pre><code>String[] lines = new String[]{"Porky.Pig", "Darth.Vader", "Donald.Duck", "George Lucas"};
  (from l in lines      
   let p = l.IndexOf('.')
   where p &gt;= 0
   select new
   {
       FirstName = l.Substring(0, p),
       LastName = l.Substring(p + 1)
   }).Dump();
  </code></pre>
  
  <p>I want to evaluate l.IndexOf('.') only once. The closest I came up with is:</p>
  
  <pre><code> String[] lines = new String[]{"Porky.Pig", "Darth.Vader", "Donald.Duck", "George Lucas"};
   Arrays.stream(lines)
         .filter(x -&gt; x.indexOf('.') &gt; 0)
         .map(x -&gt; {
             int p = x.indexOf('.');
             return new Person (x.substring(0, p), x.substring( p + 1));
         });
  </code></pre>
  
  <p>where:</p>
  
  <pre><code>public class Person {
      public Person(String firstName, String lastName)
      {
      }
  }
  </code></pre>
  
  <p>ok, based on the suggestion in the Shlomi Borovitz's answer I came up with this which makes use of this <a href="http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/tuple/Pair.html" rel="nofollow">Pair</a> class</p>
  
  <pre><code>String[] lines = new String[]{"Porky.Pig", "Darth.Vader", "Donald.Duck", "George Lucas"};
  Arrays.stream(lines)
        .map(x -&gt; Pair.of(x, x.indexOf('.')))
        .filter(x -&gt; x.getRight() &gt; 0)
        .map(x -&gt; new Person (x.getLeft().substring(0, x.getRight()), x.getLeft().substring( x.getRight()  + 1)));
  </code></pre>