Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113136 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37561 invoked from network); 11 Feb 2021 04:01:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2021 04:01:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 215981804DC for ; Wed, 10 Feb 2021 19:47:06 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,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-dm6nam11olkn2032.outbound.protection.outlook.com [40.92.19.32]) (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 ; Wed, 10 Feb 2021 19:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZCAhD/XqkR0/9Y4DLOCxXMh5T6faG1mGAVIK3BYPu9YyCnUPaZnMnmQc2OKXVmajoFXO4ZGVR2R2yQk0L4B1b9jM7swyJdHKnsYwzNMJwtUXl8zPasaY2AI5m6ehoPaqQWcCM5vZDqV50OojtnTLySvsDeiZnKoy7grG5p8b7+wvUnW33+THoxp+ups/G5iNW0gj6hvCXWOEJJ5+lK3BJX7P2ChBwtUfBaQO7moh9DH3gQXO9aPDpdC5SgccAm9//WLqQvUc2C8PNV5jcFsggbb3blbuVmrrbvHevOVfZlFfC1+Y7EWomLInbDwzYFA8v9dWK/29jpn6NV3zjGhf5g== 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=QidhUeWdXTHMawxpWBk8NT3Tw2QPQo4IDLra5qnkLwE=; b=LjxpV/b400JrEkH9Kis5vn8KV5OsXPISKgHwSLJXDpdsakcEbE9PjzxNILa51Y7/whusVa4fu38uVvunT/PPU+/nxRJzX65ed0jBUjx2LhZSNlb0PAvLfJ2TE4hiOOQfkTkhnNEtMd2PqweQpoyKRYsQ9Qfpw17uIzEXhuBnw7FKFRjtoItN1C0qJMmgKeuGVSCYzuqNrvsiKaH8NQGDkkn4ERbdEKQS26cV/ZJ7U+riq4WOA60ljqfqTBgG/cTVqMiyoSgjxNorqkaGTQIYxdKodKSDiFthPRIjG8LS8V9HpHOGArkERUW81t29bML9gk9+43aF+c+MiKDR8dL1Hw== 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=QidhUeWdXTHMawxpWBk8NT3Tw2QPQo4IDLra5qnkLwE=; b=u/LorTupl3ri97fJlTAWpIEX0hpc+VVVGOFG4ws2a6qvmUfc+0UdKMOinxFpmXQGrm4b6zYrn41sdPdaA07aqYCGakZmDOO/nJRMrdRocJahBXVr7HBiFhvdRBc/PJLTVWEUZf7SNvlv7NnntsutWabIpz7rM6sa5jt/Mv0mHpT4VNVPiAUDwal1wkmJ+p3SaVbJiiUXSOVPyBGqAlGzo5TD99o7TlZNYVsYksxM3emMaopVP+TqU+CZi9fmlHGEwYRicPG2/VMhTk/QQcSq/DTMAyOCFx4pN0eEA4b/hkNuGNvvM1PHXEZ05+lfBF2tFumKD8jkyIZwxfxX9JrxBg== Received: from CO1NAM11FT029.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::45) by CO1NAM11HT046.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25; Thu, 11 Feb 2021 03:47:03 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:3861::41) by CO1NAM11FT029.mail.protection.outlook.com (2a01:111:e400:3861::214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25 via Frontend Transport; Thu, 11 Feb 2021 03:47:03 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3825.030; Thu, 11 Feb 2021 03:47:03 +0000 To: PHP internals Thread-Topic: RFC: CachedIterable (rewindable, allows any key&repeating keys) Thread-Index: AQHXACLkMdQqZoaVtUy2vSZWXRDmOQ== Date: Thu, 11 Feb 2021 03:47:03 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:5BAE9B68938E5192C9CF9C88B4F093EC26EE08AC7DF24A4672A533A8B02B8AB5;UpperCasedChecksum:AAA05DE5CDF4001E9B75C67AF288E647B392C6D52D7AC62DDA4B219E9CAE88B9;SizeAsReceived:6825;Count:41 x-tmn: [O6aH6aeWLzvqqQZ3erc7IZX/4fG+/3PaCs5HTxKprv3Z8V8S/rUbnlcU6mTjOzd1] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: d7f6753c-f3de-4cd7-9c80-08d8ce3fb1d1 x-ms-traffictypediagnostic: CO1NAM11HT046: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: US13HyS/EiwxXRNXtTy74aa4evLlsNZQorGL0B2vn/jIiABggeKA54u/gbtFnYNcPcZQyqwtvrb7/10gVgh3PE45efbxgPt5QuBt1P1xoB3q77xHvqT7UUmSwQWRD7cn8u+DoRQNyyOWP2zigFt02OqmCvkUD5u4SiXVmQk86essA0gByIE96DnxWtUQjeCRYCPKQ2eSIKxzk1MPoq5iCOV+NRQFIf3hExpZJCPb5+uK3itamcnsluFxIiiyrjdnqTW9JxLyetwmo3N8ZVG2bVUocdTcY40n5MAzISolVSYH+lJv6+55Pn9wOB6VTTBQIE3BomBuKr2p1O0vMuBBb60Pk5yTG8QU19+7hW46BNmKY1tcqXWoQGufC7k4qCUqiPTNkq38LsH/c8OzJJKoeASqkwwvOLCXTTPn40hikg0zvB/lZmitsHaGq6y69Feu x-ms-exchange-antispam-messagedata: hlny9w7Mtquc5PodJ3iyalXsj8kz0sQlKN7VdpZS2UZ+OmmFdNFbycNPFJdDHvKOn58SnRhNlg35r9UHhSA7L4dmXyyj1se2hQt+srj8Qwg/sZlhtWnvrKQHVQ/nzjblQlMyNQ4GsRc53CyZHAWtEpxDk9p450j6986spPmFjaDRzELwTCoq7gUVRjiTx+i30anU9yT65WZ2XplJEYOSvQ== 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: CO1NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: d7f6753c-f3de-4cd7-9c80-08d8ce3fb1d1 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Feb 2021 03:47:03.3421 (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: CO1NAM11HT046 Subject: 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 Cache= dIterable,=0A= which eagerly evaluates any iterable and contains an immutable copy of the = 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, JsonSer= ializable=0A= {=0A= public function __construct(iterable $iterator) {}=0A= public function getIterator(): InternalIterator {}=0A= public function count(): int {}=0A= // [[$key1, $value1], [$key2, $value2]]=0A= public static function fromPairs(array $pairs): CachedIterable {}=0A= // [[$key1, $value1], [$key2, $value2]]=0A= public function toPairs(): array{} =0A= public function __serialize(): array {} // [$k1, $v1, $k2, $v2,...]=0A= public function __unserialize(array $data): void {}=0A= =0A= // useful for converting iterables back to arrays for further processin= g=0A= public function keys(): array {} // [$k1, $k2, ...]=0A= public function values(): array {} // [$v1, $v2, ...]=0A= // useful to efficiently get offsets at the middle/end of a long iterab= le=0A= public function keyAt(int $offset): mixed {}=0A= public function valueAt(int $offset): mixed {}=0A= =0A= // '[["key1","value1"],["key2","value2"]]' instead of '{...}'=0A= public function jsonSerialize(): array {}=0A= // dynamic properties are forbidden=0A= }=0A= ```=0A= =0A= Currently, PHP does not provide a built-in way to store the state of an arb= itrary iterable for reuse later=0A= (when the iterable has arbitrary keys, or when keys might be repeated). It = 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 Iterator= =0A= 3. In the future, providing internal or userland helpers such as iterable_f= lip(iterable $input), iterable_take(iterable $input, int $limit),=0A= iterable_chunk(iterable $input, int $chunk_size), iterable_reverse(), e= tc (these are not part of the RFC)=0A= 4. Providing memory-efficient random access to both keys and values of arbi= trary key-value sequences =0A= =0A= Having this implemented as an internal class would also allow it to be much= more efficient than a userland solution=0A= (in terms of time to create, time to iterate over the result, and total mem= ory usage). See https://wiki.php.net/rfc/cachediterable#benchmarks=0A= =0A= After some consideration, this is being created as a standalone RFC, and go= ing in the global namespace:=0A= =0A= - Based on early feedback on https://wiki.php.net/rfc/any_all_on_iterable#s= traw_poll (on the namespace preferred in previous polls)=0A= 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 consen= sus.=0A= =0A= An earlier attempt by others on creating a policy for namespaces in gener= al(https://wiki.php.net/rfc/php_namespace_policy#vote) also did not pass.= =0A= =0A= Having even 40% of voters opposed to introducing a given namespace (in pr= e-existing modules)=0A= makes it an impractical choice when RFCs require a 2/3 majority to pass.= =0A= - While some may argue that a different namespace might pass,=0A= https://wiki.php.net/rfc/any_all_on_iterable_straw_poll_namespace#vote ha= d a sharp dropoff in feedback after the 3rd form.=0A= I don't know how to interpret that - e.g. are unranked namespaces preferr= ed even less than the options that were ranked or just not seen as affectin= g the final result.=0A= =0A= Any other feedback unrelated to namespaces?=0A= =0A= Thanks,=0A= - Tyson=