Go Closures: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 5: Line 5:
=Overview=
=Overview=


A closure is an anonymous function declared within a block. The function has access to the local variables it has access to its creation for the duration of its life.
A closure is an anonymous function declared within a block. The function continues to have access to the local variables it had access when it was created for the duration of its life.


<pre>
<pre>

Revision as of 04:42, 28 March 2016

Internal

Overview

A closure is an anonymous function declared within a block. The function continues to have access to the local variables it had access when it was created for the duration of its life.

inClosuresScope := 10

var c = func (i int) {
    inClosuresScope += i
}

s := []int {1, 2, 3, 4, 5}

for _, value := range s {
     c(value);
}

More about closures is available here.