What are good examples of: "operation of a program should map input values to output values rather than change data in place"

functional-programming, scala

Solution

I'd say it's the difference between:

var counter = 0
def updateCounter(toAdd: Int): Unit = {
  counter += toAdd
}
updateCounter(8)
println(counter)

and:

val originalValue = 0
def addToValue(value: Int, toAdd: Int): Int = value + toAdd
val firstNewResult = addToValue(originalValue, 8)
println(firstNewResult)

This is a gross over simplification but fuller examples are things like using a foldLeft to build up a result rather than doing the hard work yourself: foldLeft example

Problem

I came across this sentence in Scala in explaining its functional behavior. operation of a program should map input of values to output values rather than change data in place Could somebody explain it with a good example? Edit: Please explain or give example for the above sentence in its context, please do not make it complicate to get more confusion

Original source