Function 这个成语叫斯卡拉。制作def以缩短语句?

Function 这个成语叫斯卡拉。制作def以缩短语句?,function,scala,functional-programming,Function,Scala,Functional Programming,我试图避免在参数列表中键入长句。 这是一个习惯用法吗 def createRecaptchaHtml: String = { def config(s: String) = Play.current.configuration.getString(s).toString() ReCaptchaFactory.newReCaptcha(config("recaptcha.publicKey") , config("recaptcha.privateKey"), false).c

我试图避免在参数列表中键入长句。
这是一个习惯用法吗

  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)

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

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