Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108797 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72111 invoked from network); 1 Mar 2020 15:52:47 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 1 Mar 2020 15:52:47 -0000 To: internals@lists.php.net References: Date: Sun, 1 Mar 2020 15:11:27 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: Support rewinding of generators From: ajf@ajf.me (Andrea Faulds) Message-ID: Hi again, Andrea Faulds wrote: > I am not sure if I think this is a good idea… for one thing it may not > be necessary to add support in core for this, because you could easily > write a userland Iterator class that wraps a generator-returning closure > and (re-)invokes it for you. If you do it yourself that way, it's clear > what's actually happening behind the scenes at least. > > If it must be done, perhaps the code must explicitly opt-in to being > rewindable somehow? That would avoid problems with rewinding generators > which aren't designed for it. Now that I think about it, such a wrapper class could be part of the PHP standard library. Spl already provides InfiniteIterator and NoRewindIterator, so an InfiniteGenerator class would feel right at home, I think! Thanks, Andrea