Play2's anorm has a nice DSL of result parser:
case class User(id:Pk[String], name:String)
object User {
val parser = get[String]("id") ~ get[String]("name") map {
case id ~ name => User(id,name)
}
}
I don't understand this part case id ~ name
, why there can be a ~
between two variables?
I see case
normally as:
case id => _
case (a,b) => _
case Array(a, _*) => _
But I don't see case id ~ name
.
The source of ~
is here: https://github.com/playframework/Play20/blob/master/framework/src/anorm/src/main/scala/SqlParser.scala#L49
It defines a case class ~
:
case class ~[+A, +B](_1:A, _2:B)
And I write a simple test:
case class ~[+A, +B](_1:A, _2:B)
new ~("a","b") match {
case x ~ y => println(x , y)
}
It prints a,b
, but why the syntax is case x ~ y
?