4 ms·
> Iterating over something requires knowing where you are in the sequence, so of course you would need to implement a method to get the current position of the
by bvrmn 1y ago
> Iterating over something requires knowing where you are in the sequence, so of course you would need to implement a method to get the current position of the iteration.
No you don't. Other languages don't require it. There is no issue to get a position outside of iterator and it's more generic approach.
- jw1224 1y agoI don’t think you understand the purpose of PHP’s Iterator interface.
- bvrmn 1y agoLet me guess. To somehow patch iteration on associative arrays? And instead of bringing pairs or tuples as first class citizens it extends iterators with `key` and `value`. And now any Iterator implementation should track own sequentially increasing key. Very nice design indeed.
- jw1224 1y agoAssociative arrays are iterable internally without needing an interface or key tracking. You can just foreach them. > Let me guess. This just proves my point, you call this a “hot mess” whilst completely misunderstanding what it’s even used for. The Iterator interface isn’t even used in the comment you first replied to.