Difference between closures and functions

1

Closures is a function in Groovy? Is there any difference between them?

    
asked by anonymous 05.03.2018 / 18:58

1 answer

1

A function is something much simpler. The closure assumes more things.

It certainly uses a function, but it needs to be first order, that is, it needs to be able to be used as data, it can be used wherever it makes sense, including storing in variables or passing as an argument or function return.

But this would still only be an anonymous function, possibly with a lambda syntax.

You still need to capture local variables from where it was defined, and these variables need to be part of the scope of the cloaking function, even if it is used outside the scope where it was declared.

More can be seen in What's the difference between a lambda expression, a closure, and a delegate? , even though of being another language.

    
06.03.2018 / 00:17