rfc:iterator_chaining
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:iterator_chaining [2021/03/20 20:34] – created maxsem | rfc:iterator_chaining [2021/03/21 14:32] (current) – maxsem | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: Iterator chaining |
* Version: 0.9 | * Version: 0.9 | ||
* Date: 2021-03-20 | * Date: 2021-03-20 | ||
Line 7: | Line 7: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The elevator pitch for the RFC. The first paragraph | + | SPL provides a set of iterators that allow feeding one into another |
+ | |||
+ | <code php> | ||
+ | $iterator = new RegexIterator($myIterator, | ||
+ | $iterator = new CallbackFilterIterator($iterator, | ||
+ | $iterator = new LimitIterator($iterator, | ||
+ | $iterator = new InfiniteIterator($iterator); | ||
+ | </ | ||
+ | |||
+ | Phew, that' | ||
+ | <code php> | ||
+ | $iterator = new InfiniteIterator(new LimitIterator(new CallbackFilterIterator(new RegexIterator($myIterator, | ||
+ | </ | ||
+ | |||
+ | Note how the order of writing is gorgeously opposite to the order of data flow. | ||
+ | |||
+ | Can we make it better? | ||
===== Proposal ===== | ===== Proposal ===== | ||
+ | I like how this is implemented Rust. Translated to PHP, that would look like: | ||
+ | <code php> | ||
+ | $iterator = $myIterator-> | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Wouldn' | ||
+ | |||
+ | **Create a trait** that extends iterators and allows to feed them into other iterators: | ||
<code php> | <code php> | ||
trait IteratorChain { | trait IteratorChain { | ||
public function skip(int $count): LimitIterator {} | public function skip(int $count): LimitIterator {} | ||
- | public function | + | public function |
+ | public function skipAndLimit(int $numToSkip, int $limit): LimitIterator {} | ||
+ | public function regex(string $regex, int $mode = RegexIterator:: | ||
public function callbackFilter(callable $callback): CallbackIterator {} | public function callbackFilter(callable $callback): CallbackIterator {} | ||
public function noRewind(): NoRewindIterator {} | public function noRewind(): NoRewindIterator {} | ||
public function cached(int $flags = CachingIterator:: | public function cached(int $flags = CachingIterator:: | ||
- | public function multiple(int $flags = MultipleIterator:: | + | public function multiple(int $flags = MultipleIterator:: |
+ | public function infinite(): InfiniteIterator | ||
} | } | ||
</ | </ | ||
+ | |||
+ | **Use this trait** in all SPL iterators, where appropriate. Full list: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | What breaks, and what is the justification for it? | + | None. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 31: | Line 69: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Need to | + | Need to decide on precise details |
- | + | ||
- | ===== Unaffected PHP Functionality ===== | + | |
- | List existing areas/ | + | |
- | + | ||
- | This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. | + | |
===== Future Scope ===== | ===== Future Scope ===== | ||
Line 42: | Line 75: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Include these so readers know where you are heading and can discuss the proposed voting options. | + | Accept this RFC (yes/no)? - 2/3 votes required |
===== Patches and Tests ===== | ===== Patches and Tests ===== |
rfc/iterator_chaining.1616272483.txt.gz · Last modified: 2021/03/20 20:34 by maxsem