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
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
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
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
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
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
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
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
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,
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.)
> >
> > ---
>
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
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,
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
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
Hello internals,
(this is my first email to this list, hopefully I'm doing ok.)
(I sent this message before, but I think it was rejected due to html/multipart
and lack of [PHP-DEV] in subject)
Background /
Hello internals,
(this is my first email to this list, hopefully I'm doing ok.)
(I sent this message before, but I think it was rejected due to html/multipart)
Background / motivation:
Currently in PHP we have an
Hello internals,
(this is my first email to this list, hopefully I'm doing ok.)
Background / motivation:
Currently in PHP we have an interface "Iterator", and a final class
"Generator"
(and others) that implement
18 matches
Mail list logo