Re: "Reader" as alternative to Iterator

From: Date: Mon, 03 Jul 2017 02:15:30 +0000
Subject: Re: "Reader" as alternative to Iterator
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-99696@lists.php.net to get a copy of this message
On Sat, Jul 1, 2017 at 1:38 PM, Andreas Hennings <andreas@dqxtech.net> 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 existing interface Iterator will remain unchanged. > Rather than introduce a new kind of iteration mechanism, how about just creating a library in userspace which provides a proxy interface: class Reader implements Iterator { protected $it; public function __construct(iterable $it) { $this->it = $it; } public function current/key/next/rewind/valid() { $this->it->current/key/next/rewind/valid(); } public function read() { /* What a reader should be */ } } Then you can use any already extant iterable via: $reader = new Reader($iterable); This could live in a composer/packagist library and work on already released versions of PHP. Or is there something I'm missing? -Sara

« previous php.internals (#99696) next »