Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:32:13+00:00 2026-05-30T06:32:13+00:00

Play2’s anorm has a nice DSL of result parser: case class User(id:Pk[String], name:String) object

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:32:15+00:00Added an answer on May 30, 2026 at 6:32 am

    You’re already halfway there. It is possible because Scala lets you do that for all types that have been declared with two type parameters.

    For example:

    scala> case class Foo[X,Y]()
    defined class Foo
    
    scala> val x: Int Foo Double = Foo[Int,Double]()
    x: Foo[Int,Double] = Foo()
    

    While it may seem odd at first, it’s actually a really nice property as this syntax can make things more readable. Consider the following example where a custom type for a tuple is defined:

    class |::|[A, B](val left: A, val right: B)
    
    object |::| {
      def unapply[A, B](o: A |::| B) = Some((o.left, o.right))
    }
    

    Here, A |::| B is used as infix notation for |::|[A, B]. On the other hand, scala also allows infix notation for pattern matching (thanks to incrop for the reminder), as in case of the constructor in the following example:

    new |::|("Hello","World") match {
      case l |::| r => Console println (l + "," + r)
      case _ =>
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We can write sqls like following in play2's anorm: def findById(id: String): Option[Link] =
This is a sample code from play2's built-in's zentasks: object Project { // --
I'm using Play2 with anorm. I think the spirit of anorm is write plain
I found that the row parsers of play2's anorm depend on the meta data
I'm wanting to play around with creating an LR parser generators. Does anyone know
I can't get the attr function to change the class and keep it until
This is the document of how to uploading a file in play2: https://github.com/playframework/Play20/wiki/ScalaFileUpload But
I know there is one for play1, but I don't find any for play2.
Play has a nifty file upload mechanism where uploads can be performed like so:
Play Framework has the file routes. This file list all the routes needed by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.