Skip to content

Instantly share code, notes, and snippets.

@yunchih
Last active August 29, 2015 14:06
Show Gist options
  • Save yunchih/4b54b0711c9b8b05c27f to your computer and use it in GitHub Desktop.
Save yunchih/4b54b0711c9b8b05c27f to your computer and use it in GitHub Desktop.

###Problem 1

Here's an excerpt from a model class in Play.

SQL("update entry set title={title}, content={content}, date={date} where id = {id}").on(
        'title -> entry.title,
        'content -> entry.content,
        'date -> entry.date,
        'id -> entry.id
      ).executeUpdate()

In method on, mapper key written as 'foo seems to be a convention accepted by the Play community. But why it is not causing a unclosed string syntax error?


###Problem 2

Here's another excerpt from Play doc

 val languages: List[(String, String, Boolean)] = SQL(
    """
      select * from Country c 
      join CountryLanguage l on l.CountryCode = c.Code 
      where c.code = {code};
    """
  )
  .on("code" -> countryCode)
  .as {
    str("name") ~ str("language") ~ str("isOfficial") map {
      case n~l~"T" => (n,l,true)
      case n~l~"F" => (n,l,false)
    } *
  }

Notice the strange ~ notation. At first sight, I don't believe it's implemented by Scala. But it is. Here is its type definition. It's a method of RowParser that takes another RowParser and returns yet another RowParser of type RowParser[~[A, B]]. I'm digging further into type ~[A, B] and navigate to its definition here. The problem is: I cannot find its source code in Github. Neither can I find the source of another ~ ( as specified here. )

Here's what you can get in Github.

How can I find them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment