Last active
December 26, 2015 00:09
-
-
Save milankinen/7062280 to your computer and use it in GitHub Desktop.
Scala ordering DSL example
This file contains 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
object OrderingDSLExample extends App { | |
case class My(num: Int, str: String) | |
val myValues = List(My(3, "foo"), My(3, "bar"), My(5, "bar"), My(5, "foo")) | |
import OrderingDSL._ | |
require(myValues.sortBy(m => (asc(m.num), asc(m.str))) == | |
List(My(3, "bar"), My(3, "foo"), My(5, "bar"), My(5, "foo"))) | |
require(myValues.sortBy(m => (asc(m.num), desc(m.str))) == | |
List(My(3, "foo"), My(3, "bar"), My(5, "foo"), My(5, "bar"))) | |
require(myValues.sortBy(m => (desc(m.num), asc(m.str))) == | |
List(My(5, "bar"), My(5, "foo"), My(3, "bar"), My(3, "foo"))) | |
require(myValues.sortBy(m => (desc(m.num), desc(m.str))) == | |
List(My(5, "foo"), My(5, "bar"), My(3, "foo"), My(3, "bar"))) | |
println("Horray!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment