Functions and Methods
Local Functions
Define a helper inside another method.
Local Functions
LocalFunctions.scala
object Main {
def main(args: Array[String]): Unit = {
val base =
def addOne(value: Int): Int = {
value + 1
}
val result = addOne(base)
println("base=" + base)
println("result=" + result)
}
}
object Main {
def main(args: Array[String]): Unit = {
val base =
def addOne(value: Int): Int = {
value + 1
}
val result = addOne(base)
println("base=" + base)
println("result=" + result)
}
}
local-functions
A local function belongs to the block where it is defined. It keeps a helper close to the code that uses it.