Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96688 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70669 invoked from network); 1 Nov 2016 02:53:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Nov 2016 02:53:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=dlundgren@syberisle.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dlundgren@syberisle.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain syberisle.net designates 96.126.116.40 as permitted sender) X-PHP-List-Original-Sender: dlundgren@syberisle.net X-Host-Fingerprint: 96.126.116.40 mail.syberisle.net Received: from [96.126.116.40] ([96.126.116.40:60696] helo=li341-40.members.linode.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BE/45-25911-DA308185 for ; Mon, 31 Oct 2016 21:53:33 -0500 Received: from localhost (admin.local [127.0.0.1]) by li341-40.members.linode.com (Postfix) with ESMTP id CC8DA25253 for ; Mon, 31 Oct 2016 22:53:30 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at syberisle.net Received: from li341-40.members.linode.com ([127.0.0.1]) by localhost (syberisle.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D7OEk_lAuElW for ; Mon, 31 Oct 2016 22:53:30 -0400 (EDT) Received: from oo-laptop.local (cpe-65-29-233-211.wi.res.rr.com [65.29.233.211]) (Authenticated sender: dlundgren@syberisle.net) by li341-40.members.linode.com (Postfix) with ESMTPSA id 62F7425252 for ; Mon, 31 Oct 2016 22:53:30 -0400 (EDT) To: internals@lists.php.net References: <44244cfd-c8ad-e0a9-4e70-380a8a8c940c@syberisle.net> <01f2f3da-592b-fd23-709d-ad620422f56d@fleshgrinder.com> <7fb9a5d5-318d-7ed3-59eb-d9845ed5dec1@gmail.com> <5219c048-66f1-be9a-ae3c-15633a65e263@garfieldtech.com> Message-ID: <82bf29ec-1971-cbe5-2e0b-3c9e0bd94eb7@syberisle.net> Date: Mon, 31 Oct 2016 21:53:29 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Allow Iterator to be used with current, next, reset, key functions From: dlundgren@syberisle.net (David Lundgren) On 10/31/16 4:49 PM, Larry Garfield wrote: > If we're concerned about pw0ning the "first" function name, perhaps it's > time to start a new prefix: > > iter_first(iterable) > iter_first_key(iterable) > array_last(array) > array_last_key(array) > > Which gives a natural place to start putting iterable-friendly > alternates of the various array_* functions, for those that make sense. > (think iter_fold(), iter_map(), iter_filter(), etc.) > > (Insert debate about parameter order and method-based alternatives here.) A couple of things before my next idea: 1) I don't know if this has been proposed before 2) I do not understand the internals code well enough 3) This is probably something for PHP 8, but it'd be great for PHP 7.2! 4) ArrayIterator does what I am proposing, but adds overhead for users What if we made ArrayIterator transparently wrap all array's? Then we could go with iter_* functions, deprecate array_* functions, and have syntax that flows like the following? === $ary = [1,2,3]; $ary->current(); // returns 1 $ary->reset(); // array is now at index:0 $ary->next(); // array is now at index:1 current => 2 $ary->key(); // 1 // I'll bikeshed the Array type now $ary->search(2); // 1 $ary->in(2); // true $ary->keys(); // [0,1,2] // threw these in here for good measure, part of \Iterator interface? $ary->first(); // 1 $ary->last(); // 3 === Dave -- David Lundgren dlundgren@syberisle.net GPG: 0x26F54D7F