Indeed there is: it is called " val ". val
({ x: Double => val y = x + x y * y })(3)
Brackets, of course, are optional here, I just prefer their brackets when defining functions (after all, this is not Lisp). The val keyword defines a new binding in the current lexical domain. Scala does not force locals to define their scope, unlike languages โโsuch as Lisp and ML.
Actually, var also works in any field, but he believes that it is bad style to use it.
Daniel Spiewak
source share