Go Closures

From NovaOrdis Knowledge Base
Revision as of 04:43, 28 March 2016 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

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. The function together with the non local variables it references is known as a closure.

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.