Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Created January 10, 2014 04:14
Show Gist options
  • Save manjuraj/8346897 to your computer and use it in GitHub Desktop.
Save manjuraj/8346897 to your computer and use it in GitHub Desktop.
Ordering.by
scala> case class Foo(n: Int)
defined class Foo
scala> List[Foo]().sorted
<console>:10: error: No implicit Ordering defined for Foo.
List[Foo]().sorted
^
scala> implicit def ordFoo = Ordering.by[Foo, Int](_.n)
ordFoo: scala.math.Ordering[Foo]
scala> List[Foo]().sorted
res1: List[Foo] = List()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment