Created
January 10, 2014 04:14
-
-
Save manjuraj/8346897 to your computer and use it in GitHub Desktop.
Ordering.by
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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