Sorting lists by various measures of goodness def sort[A, B: Ordering](data: List[A], desc: Boolean)(measure: A =&gt; B): List[A] = {
        val baseOrdering = Ordering.by(measure)
        val ordering = if (desc) baseOrdering.reverse else baseOrdering
        data.sorted(ordering)   
    }

  private def sortOne(stats: List[One], by: String, desc: Boolean): List[One] =
    by match {
      case "good" =&gt; sort(stats, desc)(_.data.good)
      case "bad" =&gt; sort(stats, desc)(_.data.bad)
      case "gross" =&gt; sort(stats, desc)(_.data.gross)
      case "warn" =&gt; sort(stats, desc)(_.data.warn)
      case "exuberant" =&gt; sort(stats, desc)(_.data.exuberant)
      case other =&gt; stats
    }
  private def sortTwo(stats: List[Two], by: String, desc: Boolean): List[Two] =
    by match {
      case "good" =&gt; sort(stats, desc)(_.data.good)
      case "bad" =&gt; sort(stats, desc)(_.data.bad)
      case "gross" =&gt; sort(stats, desc)(_.data.gross)
      case "warn" =&gt; sort(stats, desc)(_.data.warn)
      case "exuberant" =&gt; sort(stats, desc)(_.data.exuberant)
      case other =&gt; stats
    }

  private def sortThird(stats: List[Third], by: String, desc: Boolean): List[Third] =
    by match {
      case "good" =&gt; sort(stats, desc)(_.data.good)
      case "bad" =&gt; sort(stats, desc)(_.data.bad)
      case "gross" =&gt; sort(stats, desc)(_.data.gross)
      case "warn" =&gt; sort(stats, desc)(_.data.warn)
      case "exuberant" =&gt; sort(stats, desc)(_.data.exuberant)
      case other =&gt; stats
    }


Actually there are more classes. They all have same fields like good, gross, bad, warn.

These classes that are in methods have all similar fields good, gross, bad, warn. I can't rewrite classes.

It is working, but it looks bad. Maybe someone has some ideas?
You could try that: 

def sort[A, B: Ordering](data: List[A], desc: Boolean)(measure: A =&gt; B): List[A] = {
    val baseOrdering = Ordering.by(measure)
    val ordering = if (desc) baseOrdering.reverse else baseOrdering
    data.sorted(ordering)   
}


Then you do 

sort(listOfFirstClass, desc)(_.good)