【问题标题】:Scala unary operator usage in this example此示例中的 Scala 一元运算符用法
【发布时间】:2013-06-19 18:22:21
【问题描述】:

我正在通过以下 URL 阅读教程:http://www.smartjava.org/content/tutorial-getting-started-scala-and-scalatra-part-iii

这是一段代码:

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
  }

我没能理解的是~ 在这里被用来做什么?调用 noID* 方法时究竟发生了什么?这里是否有足够的上下文可以理解,或者~ 是我在某处看不到的一些隐含价值?

【问题讨论】:

标签: scala scalatra


【解决方案1】:

在此示例中,波浪号是一个组合符,表示将两列结果组合在一起。当像 for * 一样连续链接在一起时,这意味着返回一个结果,该结果是所有这些列一起作为单个结果对象。这意味着这些列类上有一个名为 ~ 的函数,并且您正在使用中缀表示法并调用它。实际上它更像是;

columnA.~(columnB)

【讨论】:

    猜你喜欢
    • 2017-11-30
    • 2017-03-31
    • 2013-05-06
    • 2015-02-04
    • 2016-03-08
    • 2023-04-02
    • 2016-10-28
    • 2013-09-18
    • 2017-07-02
    相关资源
    最近更新 更多