title: Understanding when and how to use Java 8 Lambdas
body: <p>I have been spending some time trying to learn some of Java 8's new features.  As an exercise, I wrote a MergeSort using some Java 8 Functional Interfaces.  I'm including the full code below (bugs/optimizations may exist, I am only interested in them if they relate to Java 8 features).  My question is, I believe there are opportunities to utilize lambda expressions when I am using my functional interfaces, but it's just not clicking in my brain yet.  It feels like everytime I am calling apply, there should be a way I can use "->" instead.  Can someone please show me the light?</p>
  
  <h3>Merge Function written using BinaryOperator Functional Interface</h3>
  
  <pre><code>public class Merge implements BinaryOperator&lt;int[]&gt;{
  
  @Override
  public int[] apply(int[] t, int[] u) {
  
      int[] result = new int[t.length + u.length];
  
      for (int i = 0, j = 0, k = 0; i &lt; result.length; i++){
  
          if( j == t.length){
              result[i] = u[k++];
          } else if (k == u.length) {
              result[i] = t[j++];
          } else {
              result[i] = t[j] &lt; u [k] ? t[j++] : u[k++];
          }
  
      }
  
      return result;
  }
  
  }
  </code></pre>
  
  <h3>MergeSort written as a java.util.function.Function</h3>
  
  <pre><code>public class MergeSort implements Function&lt;int[], int[]&gt;{
  
  Merge merge = new Merge();
  
  @Override
  public int[] apply(int[] t) {
  
      if(t.length &lt;= 1){
          return t;
      }
  
       return merge.apply( apply(Arrays.copyOfRange(t, 0, t.length / 2)), 
                           apply(Arrays.copyOfRange(t, t.length / 2, t.length )));
  
  }
  
  }
  </code></pre>
  
  <h3>Main with one simple test case</h3>
  
  <pre><code>public class MergeSortMain {
  
  public static void main(String[] args) {
  
      int values[] = {3,12,6,7,2,1,23,4,5,7,8,4,2,5,365};
  
      MergeSort mergeSort = new MergeSort();
  
      System.out.println(Arrays.toString(mergeSort.apply(values)));
  }
  
  }
  </code></pre>
  
  <p>produces </p>
  
  <pre><code>[1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 12, 23, 365]
  </code></pre>