func outerFunction(iterations int, s1, s2 string) int {
someState := 0
innerFunction := func(param string) int {
// Could have another nested function here!
totalLength := 0
// Note that the iterations parameter is available
// in the inner function (closure)
for i := 0; i < iterations; i++) {
totalLength += len(param)
}
return totalLength
}
// Now we can call innerFunction() freely
someState = innerFunction(s1)
someState += innerFunction(s2)
return someState
}
myVar := outerFunction(100, "blah", "meh")