title: Sorting a ListBuffer by Position
body: <p>Unfortunately, <code>scala.util.parsing.input.Position</code> does not extend <code>Ordering[Position]</code>.</p>
  
  <p>To sort a <code>ListBuffer</code> of errors based on their position, I use the following code:</p>
  
  <pre><code>semanticErrors.sortBy(_.pos)(new Ordering[Position] {
    def compare(x: Position, y: Position): Int = x.line - y.line 
  }).toList
  </code></pre>
  
  <p>I'm sure this can be done more elegantly. But how? For example, I noticed that <code>Position</code> implements <code>&lt;</code>. Is there a generic wrapper which turns something that supports <code>&lt;</code> into an <code>Ordering</code>?</p>
  
  <hr>
  
  <p>Interestingly, this seems to be a lot easier when converting to a <code>List</code> first:</p>
  
  <pre><code>semanticErrors.toList.sort((a, b) =&gt; a.pos &lt; b.pos)
  </code></pre>
  
  <p>But this is probably not the most efficient solution. An in-place sort of the <code>ListBuffer</code> would be ideal.</p>