Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I want to point out that <a href="http://www.scala-lang.org/api/current/index.html#scala.math.Ordered" rel="nofollow noreferrer"><code>Ordered</code></a> has been mostly phased out of the Scala standard library in favor of the more general <a href="http://www.scala-lang.org/api/current/index.html#scala.math.Ordering" rel="nofollow noreferrer"><code>Ordering</code></a>. Unless you have a good reason for using the former that I don't know about, the latter is probably a better choice.</p> <p>It might not be much better, but if you use <code>Ordering</code> at least you can get rid of the ugly <code>&lt;%</code> operators. I'd also recommend using the same lambda shorthand that @maasg suggested (note that you can't use it for the more complex Random lambda though):</p> <pre><code>def qsortHead[A: Ordering](xs: Stream[A]) = qsort(xs)(_.head) def qsortLast[A: Ordering](xs: Stream[A]) = qsort(xs)(_.last) def qsortRandom[A: Ordering](xs: Stream[A]) = qsort(xs)(ys =&gt; ys(rng.nextInt(ys.length))) </code></pre> <p>You can look at this question if you want more info on the difference between the view-bound <code>Ordered</code> and context-bound <code>Ordering</code>: <a href="https://stackoverflow.com/questions/4465948/what-are-scala-context-and-view-bounds"><em>What are Scala context and view bounds?</em></a></p> <p>Due to the way that Scala handles generic types and does type inference, you're going to be stuck with a bunch of boilerplate pretty much no matter what. The above is probably about as succinct as you're going to be able to get.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload