这是成语Scala。制定def以缩短陈述?

时间:2012-04-13 16:38:53

标签: function scala functional-programming

我试图避免在参数列表中输入长句 这是一个习惯用Scala存档的方式吗?

  def createRecaptchaHtml: String = {
    def config(s: String) = Play.current.configuration.getString(s).toString()
    ReCaptchaFactory.newReCaptcha(config("recaptcha.publicKey") , config("recaptcha.privateKey"), false).createRecaptchaHtml(null, null)

1 个答案:

答案 0 :(得分:9)

是的,这种本地方法非常适合该应用。另一种方法是在范围中导入所需的实例方法:

def createRecaptchaHtml: String = {
  import Play.current.configuration.getString
  ReCaptchaFactory.newReCaptcha(
    getString("recaptcha.publicKey").get,
    getString("recaptcha.privateKey").get, 
    false
  ).createRecaptchaHtml(null, null)
}