rfc:iteration-tools
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:iteration-tools [2008/11/03 14:57] – changed status and date amenthes | rfc:iteration-tools [2008/11/03 15:05] – typos amenthes | ||
---|---|---|---|
Line 27: | Line 27: | ||
==== Why do we need tools for iteration ==== | ==== Why do we need tools for iteration ==== | ||
- | Given that iteration is such a recurrent situation and conforming to the DRY principle, but also in total respect with common sense, an abstraction is required. Thankfully, patterns regarding iteration were observed almost | + | Given that iteration is such a recurrent situation and conforming to the DRY principle, but also in total respect with common sense, an abstraction is required. Thankfully, patterns regarding iteration were observed almost |
For example: | For example: | ||
* some of the functions modify data in the set | * some of the functions modify data in the set | ||
Line 44: | Line 44: | ||
While these classes do their job they have some shortcomings: | While these classes do their job they have some shortcomings: | ||
* They only iterate over Traversables. Supporting arrays would be nice (Indeed, we have array_map(), | * They only iterate over Traversables. Supporting arrays would be nice (Indeed, we have array_map(), | ||
- | * FilterIterator, | + | * FilterIterator, |
* CallbackFilterIterator, | * CallbackFilterIterator, | ||
Line 147: | Line 147: | ||
</ | </ | ||
- | While the 1.2 example is very similar to 2.1 it differs from it in that it's not passing the iterator to the callback function and, of course, the fact that I use a function instead of an object. Another difference is that present implementation of CallbackFilterIterator (as documented on http:// | + | While the 1.2 example is very similar to 2.1 it differs from it in that it's not passing the iterator to the callback function and, of course, the fact that I use a function instead of an object. Another difference is that present implementation of CallbackFilterIterator (as documented on http:// |
- | =====Some | + | =====Some |
As you have seen, my proposal includes a function called walk() which does exactly the same thing as a foreach construct. The real useful thing this function provides is the ability to mimic scope inside a foreach block. So, for example: | As you have seen, my proposal includes a function called walk() which does exactly the same thing as a foreach construct. The real useful thing this function provides is the ability to mimic scope inside a foreach block. So, for example: | ||
Line 192: | Line 192: | ||
Python: | Python: | ||
* http:// | * http:// | ||
- | * http:// | + | * http:// |
- | + | ||
- | + | ||
- | ===== Changelog ===== | + | |
- | + | ||
- | + | ||
rfc/iteration-tools.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1