Exploring Range-over Functions
spec: add range over int, range over func
go - What is "range" actually? Is it a function? - Stack Overflow
Preview: ranging over functions in Go
Videos
I published an article about Exploring Go's experimental Function Iterators feature.
I talk about some exciting features and patterns that this feature could enable. One particular one is how it can be used to manage cleaning up resources.
Please take a read and let me know how you think this experimental feature can be helpful in your workflow
Range is one of the keywords according to the spec.
The following keywords are reserved and may not be used as identifiers. break default func interface select case defer go map struct chan else goto package switch const fallthrough if range type continue for import return var
For statements with range clause
A "for" statement with a "range" clause iterates through all entries of an array, slice, string or map, or values received on a channel. For each entry it assigns iteration values to corresponding iteration variables if present and then executes the block.
RangeClause = [ ExpressionList "=" | IdentifierList ":=" ] "range" Expression .
A for with a range clause iterates over arrays, slices, map, strings and values received on a channel. The range keyword is syntax used by the compiler to distinguish this type of iteration from other iteration in a for statement.
The compiler implements for with a range clause. The specification describes for with a range clause in detail.