Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96681 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40088 invoked from network); 31 Oct 2016 18:07:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Oct 2016 18:07:18 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.172 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.213.172 mail-yb0-f172.google.com Received: from [209.85.213.172] ([209.85.213.172:32827] helo=mail-yb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/D1-25911-55887185 for ; Mon, 31 Oct 2016 13:07:18 -0500 Received: by mail-yb0-f172.google.com with SMTP id o7so11104011ybb.0 for ; Mon, 31 Oct 2016 11:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Z53z4/Qqf8O5otn+Ob4Jc/SGo5Kt5Hz6ueCUOlA5GuE=; b=GK/j9neIK8rZiM7XoadOo8H9HB5m18EtcVJ360oIbKSFe4rWHTmEITuu7xgiRzVo+n uh0MoO9rmsdGqpqDwj3OVNM4DTNph/AI7KDdowPtFJfecPRHMllqJieK+gVatDgERFzu q2PnoLg5yDPpZ5cSg4LQy46YIrceQGhaDEq8+6nt8c+OpQW5EKNwW7Wp3OamwOPuNlG1 026xZFs9fSuC486KTiYmIhgbCUUyxqkmzhjrLBj0ziOYM1iWS1B3ALDtCcEVPpXKFl/l ZwAE6/9/heBbyiEyTIX4pa/8Wn8YzE/9vYjUMkOfT44ZHO7yeRellYIxR/4pl8lHlH4x WiXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Z53z4/Qqf8O5otn+Ob4Jc/SGo5Kt5Hz6ueCUOlA5GuE=; b=H37mDRTBQg2qabsEIK8sAaBVDUsb2iPg/JcdM0m6eAma7mXuQOPpGRNZtlqBbpthTa 6TrA3wiBAsWlPc2hZ22T+3wJ4cii0YNVqhJJlfteKbqUURdvSeotcYVi/G414W5mFHFf sVkKYwfSlYD8lkLJxsmBhk+ny9xpSDdbkLrRVnQ/aaWvh2ZK+aFS6wIS34bSmwrEjLVP fgIgmsrc3qOI4UL9WwLj2raThAWYcs6PllzHRxV8ROE0yTC3afnbuf4YA3NZQK++y1Xv zIpuv/uhyf9bjAceseVmjckdafWKByWjxGAGESK+jAh3WdYzBzYRq0NKkm70yeeSKwOD l3Nw== X-Gm-Message-State: ABUngvdmc1dWg1VLAh5yn3EtU/VxLgV7vM+QYG4aHZ4TDZgPm89tWqvzbIOM+hbQXOAFgRcvtCUSNPElqqgh5A== X-Received: by 10.37.79.84 with SMTP id d81mr24425678ybb.175.1477937234552; Mon, 31 Oct 2016 11:07:14 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.13.200.3 with HTTP; Mon, 31 Oct 2016 11:07:13 -0700 (PDT) In-Reply-To: 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> Date: Mon, 31 Oct 2016 12:07:13 -0600 X-Google-Sender-Auth: 4NIX6_-YKjArexvr4Sa5LfuTDKU Message-ID: To: Larry Garfield Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Allow Iterator to be used with current, next, reset, key functions From: levim@php.net (Levi Morrison) On Mon, Oct 31, 2016 at 11:57 AM, Levi Morrison wrote: > On Mon, Oct 31, 2016 at 11:27 AM, Larry Garfield wrote: >> On 10/31/2016 11:26 AM, Alice Wonder wrote: >>> >>> On 10/30/2016 10:19 AM, Rowan Collins wrote: >>> >>>> >>>> - deprecate reset(), end(), each(), and key() >>>> - introduce array_first(), array_last(), array_first_key() and >>>> array_last_key() >>>> - document replacements for whatever other use cases we can find >>>> examples of >>>> >>> >>> As a user I certainly like those names better. Semantic function names are >>> a definite win in my view. >> >> >> >> Question: Now that we have "iterable" as a type, should we be adding more >> array-specific functions or should such operations be designed, and named, >> to operate on any iterable? (first(), first_key(), etc.) > > At least for last and last-key I do not think we should make them work > with any iterable. My reasoning is that we do not want to consume the > iterator for them because many iterators are not rewindable (such as > generators). The first and first-key routines should generally work > because `rewind(); valid(); current(); rewind();` doesn't contain a > `next()` call. > > Rewinding without iterating works for generators: https://3v4l.org/O7ZKO > Rewinding after a next() call: https://3v4l.org/QI434 Additionally consuming the iterator would be an algorithmic complexity of O(n) whereas for an array would just be O(1). So not only is it annoying that the iterator is consumed and can't be guaranteed to be rewound it is also costly. The first and first-key routines do not have these issues.