Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101728 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77646 invoked from network); 30 Jan 2018 00:17:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2018 00:17:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.27 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.27 out3-smtp.messagingengine.com Received: from [66.111.4.27] ([66.111.4.27:44129] helo=out3-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/0F-24062-C79BF6A5 for ; Mon, 29 Jan 2018 19:17:04 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 17A3A20ACE for ; Mon, 29 Jan 2018 19:16:58 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Mon, 29 Jan 2018 19:16:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=Lz+Rj191TYl2QipcdidBmtLJ8Tz3b Nu3QMono77NDz0=; b=HF1iBcmwah//MVTG/KRLh+sPQTVPWOHeJmj5IFC9A9hHZ AB1w95NjZcVXq0qKVGfG/OzvXsZEFKL33/+y9PJEdtuaHXOSQXgL3WDPok4fVV6c 0UwPI2rWSVT3IZa3RgnT6Htg8zE1uzsHhR8fMeT8V/j1RHRA2VrUo+EBhiCgf0KA NHsQCB4VCxFogM3C89wNV0hCJ91gQoxCfvPSHmnK1csiNKFx2JcHI48IYw8jhA5q oSM4dXxyMB8YKWIhC3WPi95bBUFIp73kfuGnkm7fmCIHiVNEGiN9sUta7zpm54+d PJXZgZgEYRJGwo0p6dVRH73hgPyazGrj5dh8runMQ== X-ME-Sender: Received: from vulcan.localnet (216-80-30-152.s3222.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com [216.80.30.152]) by mail.messagingengine.com (Postfix) with ESMTPA id D1CAF24235 for ; Mon, 29 Jan 2018 19:16:57 -0500 (EST) To: internals@lists.php.net Date: Mon, 29 Jan 2018 18:16:54 -0600 Message-ID: <4026445.Wp3pesFrPl@vulcan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart6169622.iXkENGB1lu"; micalg="pgp-sha256"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: larry@garfieldtech.com (Larry Garfield) --nextPart6169622.iXkENGB1lu Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Monday, January 29, 2018 3:35:18 PM CST Michael Morris wrote: > On Mon, Jan 29, 2018 at 3:26 PM, Rowan Collins > > wrote: > > Nor are generators the only non-rewindable iterables you need to worry > > about, so really the only options you have are to only inspect arrays, or > > to add a big fat warning that the function may consume your iterable (or > > enter an infinite loop). > > Sorry about the double reply. What about using count() as a guard? While > there might be some countable consumables, my understand of generators is > they are often used where no prior count is available. Arrays and > ArrayObjects are countable. It's totally legit to have an object that is a consumable iterable that is also countable. (So many -ables in that sentence...) Really, these functions would be useful only on arrays, period. To allow them on anything else is just dangerous, and on other iterables there are better, more robust approaches (as discussed elsewhere in this thread). As you've demonstrated they're also quite compact and effective to do in user- space, so unless there's a massive performance difference of moving them to C they don't seem all that appropriate to add to the language directly. --Larry Garfield --nextPart6169622.iXkENGB1lu Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEcBAABCAAGBQJab7l2AAoJEODDCsAxcWF31noIAORhfDogUL1hDIz1pnhQY4lk 3AerMoOUeiyEviZf/U75a+bdMwutl6RCUibI0TqILThEa3WzAOc/fZ4WbGajYVoX r+/dPPX/3jibElkAUriQBv51AHj5y2LimpyPlYtmSdzxw0YqSkpxMmfVYREH1jMf D7aJx0bYzK8vfLmITW4dxOawnzk7HIiNxZzrhBwXE62Vlp6kZZa/fa1ktBjpBTk0 YFOvNw/wGqv4KBZFQi4hGJXgJHLJ4nBbrXWnPzU1vZsrcXJ65Pj+8RUusAAL90F1 62BC3N7xChyQOIlQOyRrAJ3VE3yqjjPr1GFzTRKDfvgr2V68J8OGx/448uQnLNA= =sZyN -----END PGP SIGNATURE----- --nextPart6169622.iXkENGB1lu--