I'm trying to avoid typing long sentences in the parameter list.
Is this an idiom Scala way to archive that?
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)
2.2. In Scala, all statements are expressions that return a value. The value of the last statement determines the value of an expression. The if expression is no different — it always returns a value. So, we can assign the result of an if expression to a value.
A Scala method is a part of a class which has a name, a signature, optionally some annotations, and some bytecode where as a function in Scala is a complete object which can be assigned to a variable. In other words, a function, which is defined as a member of some object, is called a method.
Void Function A function returns nothing, such as void , implies there is a side effect.
Yes, this kind of local methods are perfect for that application. An alternative is to import the instance methods you need in the scope:
def createRecaptchaHtml: String = {
import Play.current.configuration.getString
ReCaptchaFactory.newReCaptcha(
getString("recaptcha.publicKey").get,
getString("recaptcha.privateKey").get,
false
).createRecaptchaHtml(null, null)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With