in your example, it doesnt really highlight the difference between closures and functions. closures and functions are very similar. like how a function can take in parameters, or use variables outside of the function if they are defined in the class, a closure can do the same thing, but from within its own local scope.
psuedo code example:
class aaa {
var a = 5;
func foo (b:Int) -> Int {
return a+b; //a not defined in local scope, but we can still use it
}
}
now with a closure its the same thing, but you can use local variables in the same way a variable defined at the class level is used
class bbb {
var b = 1;
var closure;
func foo (c:Int) -> Int {
var d = b+c; //d is defined locally
closure = (val1:Int) -> Int { Int in
return val1 + b * d; //we can use b and d here! they are captured in the block now, and will remain with the block until executed
}
}
func bar () {
b = 3;
closure(5); //now we execute closure, now the variable d in foo() is being used but in a completely different scope, and even if we changed the value of b before running it, the value of b would be the original value captured in the closure when it was made aka 1 and not 3
}
}
so now if you ran foo then bar, you can see how closures differ to functions
so the real beauty is in the capturing of variables locally, to be used at a later time in possibly a completely different scope, where as functions can only use the parameters you give them and/or the variables defined in the class