I believe the correct solution to this is an OuterIterator — an
OuterIterator contains the logic to constrain the loop, for example, we
have the LimitIterator, FilterIterator, RegexIterator, etc.
See this example:
http://php.net/manual/en/class.limititerator.php#example-4473
You can build your ow
On 3 July 2017 16:58:16 BST, Andreas Hennings wrote:
>My motivation was to be able to use iterators and readers
>interchangeably.
>Readers are easier to implement as classes.
>Iterators have the benefit of the generator syntax.
>The idea is to have a library where some stuff is implemented as
>rea
2017-07-03 17:50 GMT+02:00 Andreas Hennings :
> On Mon, Jul 3, 2017 at 9:09 AM, Niklas Keller wrote:
> >
> > Hey Andreas,
> >
> > what you're trying to do here seems to be premature optimization. While
> you
> > save a bunch of method calls, your I/O will be the actual bottleneck
> there.
> > It'
On Mon, Jul 3, 2017 at 6:08 PM, Andreas Hennings wrote:
> On Mon, Jul 3, 2017 at 5:53 PM, Johannes Schlüter
> wrote:
>> On Mo, 2017-07-03 at 17:32 +0200, Niklas Keller wrote:
>>
>>> > That distinction is the reason why next() and valid() are different
>>> > methods in iterators.
>
> I would rathe
On Mon, Jul 3, 2017 at 5:53 PM, Johannes Schlüter
wrote:
> On Mo, 2017-07-03 at 17:32 +0200, Niklas Keller wrote:
>
>> > That distinction is the reason why next() and valid() are different
>> > methods in iterators.
I would rather say this is the reason why current() and valid() are
different met
On Mon, Jul 3, 2017 at 5:27 PM, Johannes Schlüter
wrote:
>
> Wouldn't SPL's NoRewindIterator be enough?
>
> $nit = new NoRewindIterator($it);
>
> foreach ($nit as $row) {
> break;
> }
> foreach ($nit as $row) {
> // continues same iteration
> }
I had not noticed this class :)
My motivation wa
On Mo, 2017-07-03 at 17:32 +0200, Niklas Keller wrote:
> > That distinction is the reason why next() and valid() are different
> > methods in iterators.
>
> Not really, Iterator::next() returns void, so could as well return
> bool.
Well, that story is a bit longer and I cut it short. Let's assum
On Mon, Jul 3, 2017 at 9:09 AM, Niklas Keller wrote:
>
> Hey Andreas,
>
> what you're trying to do here seems to be premature optimization. While you
> save a bunch of method calls, your I/O will be the actual bottleneck there.
> It's entirely fine to implement such logic in userland.
I will let
Thanks everyone so far for the replies!
I think I need to do some "homework", and come back with benchmarks
and provide real examples.
I remember that the overhead did make a difference in performance, but
I should back that up with real data.
For now just some inline replies.
On Mon, Jul 3, 201
2017-07-03 17:27 GMT+02:00 Johannes Schlüter :
> On Sa, 2017-07-01 at 19:38 +0200, Andreas Hennings wrote:
> > Hello internals,
> > (this is my first email to this list, hopefully I'm doing ok.)
> >
> > ---
> > -
> >
> > B
On Sa, 2017-07-01 at 19:38 +0200, Andreas Hennings wrote:
> Hello internals,
> (this is my first email to this list, hopefully I'm doing ok.)
>
> ---
> -
>
> Background / motivation:
>
> Currently in PHP we have an inter
On Sun, Jul 2, 2017 at 10:49 PM, Andreas Hennings wrote:
> (I wanted dedicated reader classes for different return types, e.g.
> one "RowReader", one "AssocReader", one "ObjectReader". So here I
> would need one adapter class per type. But let's focus on the simple
> case, where you can use the sa
2017-07-03 4:49 GMT+02:00 Andreas Hennings :
> Well, on a current project I made an attempt to write different
> adapters in userland.
> I finally decided that the clutter is not worth.
> So for this project I wrote everything as "readers", and not as iterators.
>
> With a native solution, one cou
Well, on a current project I made an attempt to write different
adapters in userland.
I finally decided that the clutter is not worth.
So for this project I wrote everything as "readers", and not as iterators.
With a native solution, one could do this:
function generate() {
yield 'a';
yield '
On Sat, Jul 1, 2017 at 1:38 PM, Andreas Hennings wrote:
> Hello internals,
> (this is my first email to this list, hopefully I'm doing ok.)
>
Welcome to php-internals!
> Establish a new interface in core, "Reader" or "ReaderInterface" (*).
> This interface has only one method, "->read()".
> The e
15 matches
Mail list logo