3 ms·
Defining a Go iterator is similar to defining a Python decorator that takes an argument. Both involve defining a function that returns another function, with th
by pansa2 2y ago
Defining a Go iterator is similar to defining a Python decorator that takes an argument. Both involve defining a function that returns another function, with the inner function having another function as its parameter.
This isn’t a particularly difficult concept, but manipulating functions in this way does feel unusual in such heavily-procedural languages. This has two downsides:
* Programmers who only use those languages are unfamiliar with the concept, and
* The languages’ syntaxes aren’t designed to make it particularly clear.