【问题标题】:How to call this scala method in play?如何在游戏中调用这个 scala 方法?
【发布时间】:2014-06-05 18:28:24
【问题描述】:

我遇到了以下方法here

 implicit def toLazyOr[T](cons: Constraint[T]) = new {
  def or(other: Constraint[T]) = Constraint { field: T =>
    cons(field) match {
      case Valid => other(field)
      case Invalid => Invalid
    }
  }
}

我定义了toLazyOr 方法,然后我尝试在我的代码中使用它。但是,我不确定如何使用它。 我试过了:

 val adminForm = Form(
mapping(
  "email" -> (email verifying toLazyOr(nonEmpty, minLength(4)) ) 
  )

还有:

val adminForm = Form(
    mapping(
      "email" -> (email verifying toLazyOr(nonEmpty or minLength(4)) ) 
      )

两者都不起作用,我目前的 scala 知识非常基础。 请帮忙。

【问题讨论】:

    标签: scala playframework-2.0


    【解决方案1】:

    在不太了解游戏的情况下:

    如果隐式转换在范围内,则以下内容应该起作用:

    val adminForm = Form(
      mapping(
        "email" -> (email verifying (nonEmpty or minLength(4)))
      ))
    

    这就是隐式转换的特点:您不必显式调用它们。请参阅this answer,了解有关编译器在哪里寻找隐式的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多