title: Java 8 parallel sorting vs Scala parallel sorting
body: <p>So I was just learning new Java 8, specially lambdas and date and time api. I was comparing it with scala. My basic idea was to find the execution time difference between imperative, Stream and parallel stream. So I decided to create a Library application and do some operations like searching, filtering, sorting etc. I created a Library class with a list field called books and populated it with 1000 books. Then created a functional interface for search and did some operation in all three styles. It all worked fine. My code is:</p>
  
  <pre><code>// Functional Interface
  interface Search&lt;T&gt; {
      public void search(T t);
  }
  
  // Library class
  final Library library = new Library();
  // This just creates some random book objects.
  final List&lt;Book&gt; books = collectBooks();
  
  final Search&lt;List&lt;Book&gt;&gt; parallelSearch = (bks) -&gt; library.findAndPrintBooksParallel(bks);
  
  // Parallel Operations
  private void findAndPrintBooksParallel(List&lt;Book&gt; books) {
      books.parallelStream()
          .filter(b -&gt; b.getAuthor().equals("J.K. Rowling"))
          .sorted((x,y) -&gt; x.getAuthor().compareTo(y.getAuthor()))
          .map(Book::getIsbn)
          .forEach(Library::waitAndPrintRecord);
  }
  </code></pre>
  
  <p>Now I tried to re-create the same program in scala and see whether the execution is faster or not? Surprisingly scala didn't allow me to do parallel sorting (Or may be I'm being ignorant here). My scala library is</p>
  
  <pre><code>// Again some random book objects as a list
  val books = collectBooks
  
  // Parallel operation
  books.par filter(_.author == "J.K. Rowling") map (_.isdn) foreach waitAndPrint
  </code></pre>
  
  <p>Here the <code>books.par</code> gives a ParSeq. This doesn't have a sort method. Is there any way I could create a parallel sort with my books list in scala. So I could write something like:</p>
  
  <pre><code>books.par filter(_.author == "J.K. Rowling") sortWith (_.author &lt; _.author) map (_.isdn) foreach waitAndPrint
  </code></pre>
  
  <p>Your help is much appreciated. Thanks.</p>