Store a function in a value and call it.

Function Values

FunctionValue.scala
object Main {
  def main(args: Array[String]): Unit = {
    val step = 
    val addStep = (x: Int) => x + step
    val result = addStep(4)

    println("step=" + step)
    println("result=" + result)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val step = 
    val addStep = (x: Int) => x + step
    val result = addStep(4)

    println("step=" + step)
    println("result=" + result)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val step = 
    val addStep = (x: Int) => x + step
    val result = addStep(4)

    println("step=" + step)
    println("result=" + result)
  }
}
function-value A function can be stored in a `val` like any other value. Calling it with an argument runs the function body and returns a result.