Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114790 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86483 invoked from network); 9 Jun 2021 00:07:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2021 00:07:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3C578180532 for ; Tue, 8 Jun 2021 17:22:35 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2088.outbound.protection.outlook.com [40.92.19.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 8 Jun 2021 17:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OXtHQEyqoOuJs+wXs7AX5V6FF67y0L2iN+5soq09SzZ6iFQFBxabckc6uSbDbZEqyHXaM7ulWWT3+7SBcyoJMVQesOa1iJhamtBnXMuCWWQkjq9FxqUfVm8rdr0n7Fn9PygoKbeb8ZRvlV8GLd3Wb1dHTDX3klbpidgXYCBj/q553sWsEDTk+bStHWXRRlTKxR4wY8hKJanJL1sighOeUQzErJiDBCf5Mt/bPk43dfaGxHzE5OgDmQtSIr1APxphfZ4nBOMHYsyq7hwtX/r2w8zawuBmccnC4KwZZs8bnWe1FDAocGx82fV2gd0NSKwXIN1/petuhHV6LJN/JU6ShA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/jjdD0J3QpJNH7x1h22VhDAct8Kxrn0YdQ+F49/dTxI=; b=hzJiVrFW0gN2fmHljSIm9CGTaw61OPfRQqEpUnWoxzuB3FVhFHSpes0DhfynYfpIee6M9NVJKNOOwpAw3Asylkhvod8N2PQDU+wpT+jJ4AaRtQvHthOkk8tGeAdpLjXsg5hDM7YBccFTqG6vZ0hi7M6xiXGf45V/VZIBPXoaLopjIy3ji31DEGxMBCiO+hNSqOFe+R50EdIa47x+862yUnedTESBFNm8PjGbIDCn3BZOkSPXSNUi5U9VY9dVQAX+lkprLjz3iPCoMx8zv5s58XVUuw/n9HuLVnpZEQmPypJJfOm7dfRRyHGLJZM8d6ps+nK8C1pWBSfUl+6am4FB3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/jjdD0J3QpJNH7x1h22VhDAct8Kxrn0YdQ+F49/dTxI=; b=ImURplnaD9pbtII88ADZ34tNFxS8JC6LXoAVm1fELYxseJSm99SCXkdNV4Pij5o9BFuXJ+408XCxSPan3exjFOElS4bT2pKSqRBy4rWBs/LGgPnBO9Ibdx6BQveFO5GY+HZDdxVjn0dsm3YOkNiULruhLfsLuyCZY25sOC68ep2yAr2xgEj77su6uqOJ2rKwSyoXNC1Jed+tTL6fngJsTMe6yijrEUWo7vodMa89lzNmvT2hEOH5X8SBIZ7CP7+EBDB58kbZVmzPZhkJMYgsew6y9fZOCIS09+ICECrqDNPGQNlmRKdyF9yut9l1gZBKGUhFpJORIWbuFjwxsTW4uw== Received: from BN8NAM11FT040.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::4b) by BN8NAM11HT166.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::265) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Wed, 9 Jun 2021 00:22:33 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4b::4a) by BN8NAM11FT040.mail.protection.outlook.com (2a01:111:e400:fc4b::422) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22 via Frontend Transport; Wed, 9 Jun 2021 00:22:33 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7%3]) with mapi id 15.20.4195.030; Wed, 9 Jun 2021 00:22:33 +0000 To: PHP internals Thread-Topic: RFC: CachedIterable (rewindable, allows any key&repeating keys) Thread-Index: AQHXACLkMdQqZoaVtUy2vSZWXRDmOasLeFTV Date: Wed, 9 Jun 2021 00:22:33 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:1FB8A18ECFF0680268185776A52A6501E57FBFBBB8A6722CCC41F762A6F04076;UpperCasedChecksum:89970B5EFBBC69B0CF13031010B7D9E7B005B08A2C2C06A1C927CB37BB04025C;SizeAsReceived:7075;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [uPknWB9e2H12lIzTm6sdZnukJHiOazXgRd5aP5uARNz0Y1sWl3jYvJ62e3wN0lf/] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 4e6b4691-dee9-4ded-6a3d-08d92adcad19 x-ms-traffictypediagnostic: BN8NAM11HT166: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NBc/fhoya8jHdukNFVlJPB/Xaatmlkuq7yNKlZcMXUUca06l1uO9zehEQv98xeT/89hbKBXiYNdXSH6Xh6PrYTpRJc95utlOBLbvAFf4sacYgoz30vJ+CDwm0VUKxYLPa6RX7WG4wJ5vlU7mOJkwc3/x4bXcKDG9u2TpnCqSx8j7gRCT3Y2WrqgDB4hj1f4Fgg6yLVzlIZd44rBVrt3MwPppnFADoWvYJcmf2DJw1/ZlPBhDe+qnCI+gAJjsWXxZ9Mm0kDMgUzrRNGiAYt/2Akjq7+l2J6QDv6kTeK3u8Xd3mkc2d/N+xfBP9sfNSFN1A81bh49NwMojQDHKGwAMDLEVl4lDfWXaW11Gra697kJClXjZjOStrAo8cntM1LOflL9JzDiz5tq8f6NtI9IXGpgSpWVjIm+jrBJ2eSY+y/jWfx+mjYnw618FMJngAc3A9ukv8BtlgiZsYsJ6+WH1JA== x-ms-exchange-antispam-messagedata: pyvkGq0JEjOOkwQ7xVpbfNdXg6IOvPbncYST/HrsEQJkgMWle9xqNcZwtbmvuwYXs05u+ei/6s1bBgKg2Fe/Q/budpkSD3ltwTUhAcE6RCk9ySw0pD3wvOYu6HVeiIQKaT9tEEm0zeNobWlPTt8hJnujxcfTwI6d5+D+/XphtqhLfTqwHTyYON2XgGdXfJEEok3vS+XOmJCkbeg4hpUltg== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 4e6b4691-dee9-4ded-6a3d-08d92adcad19 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Jun 2021 00:22:33.4261 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM11HT166 Subject: Re: RFC: CachedIterable (rewindable, allows any key&repeating keys) From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= > I've created a new RFC https://wiki.php.net/rfc/cachediterable adding Cac= hedIterable,=0A= > which eagerly evaluates any iterable and contains an immutable copy of th= e keys and values of the iterable it was constructed from=0A= > =0A= > This has the proposed signature:=0A= > =0A= > ```=0A= > final class CachedIterable implements IteratorAggregate, Countable, JsonS= erializable=0A= > {=0A= > =A0=A0=A0 public function __construct(iterable $iterator) {}=0A= > =A0=A0=A0 public function getIterator(): InternalIterator {}=0A= > =A0=A0=A0 public function count(): int {}=0A= > =A0=A0=A0 // [[$key1, $value1], [$key2, $value2]]=0A= > =A0=A0=A0 public static function fromPairs(array $pairs): CachedIterable = {}=0A= > =A0=A0=A0 // [[$key1, $value1], [$key2, $value2]]=0A= > =A0=A0=A0 public function toPairs(): array{} =0A= > =A0=A0=A0 public function __serialize(): array {}=A0 // [$k1, $v1, $k2, $= v2,...]=0A= > =A0=A0=A0 public function __unserialize(array $data): void {}=0A= > =A0=0A= > =A0=A0=A0 // useful for converting iterables back to arrays for further p= rocessing=0A= > =A0=A0=A0 public function keys(): array {}=A0 // [$k1, $k2, ...]=0A= > =A0=A0=A0 public function values(): array {}=A0 // [$v1, $v2, ...]=0A= > =A0=A0=A0 // useful to efficiently get offsets at the middle/end of a lon= g iterable=0A= > =A0=A0=A0 public function keyAt(int $offset): mixed {}=0A= > =A0=A0=A0 public function valueAt(int $offset): mixed {}=0A= > =A0=0A= > =A0=A0=A0 // '[["key1","value1"],["key2","value2"]]' instead of '{...}'= =0A= > =A0=A0=A0 public function jsonSerialize(): array {}=0A= > =A0=A0=A0 // dynamic properties are forbidden=0A= > }=0A= > ```=0A= > =0A= > Currently, PHP does not provide a built-in way to store the state of an a= rbitrary iterable for reuse later=0A= > (when the iterable has arbitrary keys, or when keys might be repeated). I= t would be useful to do so for many use cases, such as:=0A= > =0A= > 1. Creating a rewindable copy of a non-rewindable Traversable =0A= > 2. Generating an IteratorAggregate from a class still implementing Iterat= or=0A= > 3. In the future, providing internal or userland helpers such as iterable= _flip(iterable $input), iterable_take(iterable $input, int $limit),=0A= > =A0=A0=A0 iterable_chunk(iterable $input, int $chunk_size), iterable_reve= rse(), etc (these are not part of the RFC)=0A= > 4. Providing memory-efficient random access to both keys and values of ar= bitrary key-value sequences =0A= > =0A= > Having this implemented as an internal class would also allow it to be mu= ch more efficient than a userland solution=0A= > (in terms of time to create, time to iterate over the result, and total m= emory usage). See https://wiki.php.net/rfc/cachediterable#benchmarks=0A= > =0A= > After some consideration, this is being created as a standalone RFC, and = going in the global namespace:=0A= > =0A= > - Based on early feedback on https://wiki.php.net/rfc/any_all_on_iterable= #straw_poll (on the namespace preferred in previous polls)=0A= > =A0 It seems like it's way too early for me to be proposing namespaces in= any RFCs for PHP adding to modules that already exist, when there is no co= nsensus.=0A= > =0A= > =A0 An earlier attempt by others on creating a policy for namespaces in g= eneral(https://wiki.php.net/rfc/php_namespace_policy#vote) also did not pas= s.=0A= > =0A= > =A0 Having even 40% of voters opposed to introducing a given namespace (i= n pre-existing modules)=0A= > =A0 makes it an impractical choice when RFCs require a 2/3 majority to pa= ss.=0A= > - While some may argue that a different namespace might pass,=0A= > =A0 https://wiki.php.net/rfc/any_all_on_iterable_straw_poll_namespace#vot= e had a sharp dropoff in feedback after the 3rd form.=0A= > =A0 I don't know how to interpret that - e.g. are unranked namespaces pre= ferred even less than the options that were ranked or just not seen as affe= cting the final result.=0A= =0A= A heads up - I will probably start voting on https://wiki.php.net/rfc/cache= diterable this weekend after https://wiki.php.net/rfc/cachediterable_straw_= poll is finished.=0A= =0A= Any other feedback on CachedIterable?=0A= =0A= Thanks,=0A= Tyson=0A=