ETOOBUSY 🚀 minimal blogging for the impatient
Let’s look at a simplified implementation for what
A possible implementation that is compatible in interface but only offers a subset of the functionalities is the following:
It’s coded recursively, which in my opinion simplifies the implementation and figuring out what’s going on. Basically:
- lines 8 to 18 implment the modulino trick
- line 25 tests whether there are still new levels to iterate to, if not then the callback is called in line 26 and the call returns;
- oterhwise, lines 29 to 33 implement one of the nested loops for the
specifi level, then recurse (line 31). The recursive call has
$accumulatorwith all elements currently generated at the available levels.
The implementation is simplified in the sense that:
- hash reference
$optsis supported in the interface but ignored
- the iteration only accounts for arrays of items and does not support code references
- there is no support for returning an iterator.