Question

I am reading a tutorial via the following URL: http://www.smartjava.org/content/tutorial-getting-started-scala-and-scalatra-part-iii

Here's a snippet of code:

class BidRepository extends RepositoryBase {

  object BidMapping extends Table[(Option[Long], Long, Double, Double, String, Long, Long)]("sc_bid") {
      def id = column[Option[Long]]("id", O PrimaryKey)
      def forItem = column[Long]("for", O NotNull)
      def min = column[Double]("min", O NotNull)
      def max = column[Double]("max", O NotNull)
      def currency = column[String]("currency")
      def bidder = column[Long]("bidder", O NotNull)
      def date = column[Long]("date", O NotNull)

      def noID = forItem ~ min ~ max ~ currency ~ bidder ~ date
      def * = id ~ forItem ~ min ~ max ~ currency ~ bidder ~ date
  }

What I'm failing to grok here is what ~ is being used for here? What exactly is happening when the noID and * methods are invoked? Is there enough context here to understand, or is ~ some implicit value that I'm not seeing somewhere?

Was it helpful?

Solution

In this example, the tilde is a combinator that means combine two column results together. When continually chained together like it is for * it means return a result which is all of those columns together as a single result object. It means that there is a function on those column classes called ~ and you are using infix notation and calling it. In actuality it's more like;

columnA.~(columnB)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top