Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113151 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45665 invoked from network); 12 Feb 2021 05:29:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2021 05:29:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AA7031804B1 for ; Thu, 11 Feb 2021 21:14:45 -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=-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 NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2019.outbound.protection.outlook.com [40.92.22.19]) (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 ; Thu, 11 Feb 2021 21:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O1JJftDpKTGnpM57AuCxoISte0bPcsu2UJfZ/oJMdFwHel2dK0eMuZtp+D0Mp4THs/vPQF1qN4Z3Jzymob3jVyXHZgsq6MS28ibfIpAlbgEwhOrshDMikLW5uLHEFNe8N5GkI/UFS2UyIxIK1c4qzNKuGn3XDxVCkvcZa3mCWEEUK2hwQNznNWa7kQl9zk82sTJ880iv4kb+loYrdsuG7ie5jDe3wSTMYb3/74v3aAPESOVnD359buL1Wt6jK476L3qBI3s3lYWcOF9T7xtJz9hIaxMMq0iy119mYOEYn3hYKhXdPj6j4e0p6F3T9aItgP9Lgqp0HpNn6FVzngJ1GA== 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=1XBBAlkRJUh3VFxWyPELRpn3w6UwgsXu3M9Vz2lcjpU=; b=l1XoUTOEGd+j427qHBnGQfl31gXj0KwlDmGWJY/Otjvn48i9pVM/2FWP/yOck9H1+mVLVaDL2TSHSzKMqgu+g+6cATHM00+qYAIFl/wMVzSEvFNhsljz3AJ9V4WYNHvZhtfrfAdMGNbBVQkFmAPABzBnK9vm1ubxgKd44zj+FknX9ikXjgmzjNKiCAzIGoy96+83fx9/51DgTWNC5l0FNDnZHJDwJRkNWU1Qr0OTT/A1HGY9IQc+73kbAD5GiGLmV2bosilPIr/QFa5yN4IwdA+oV2isr4M2/wXRI4Hgd7tpIY2su04wmRvBKeCPk9VNs+62iQn//58u85Wel2XuZQ== 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=1XBBAlkRJUh3VFxWyPELRpn3w6UwgsXu3M9Vz2lcjpU=; b=lqUH/Tb1kscIoCK9CmwyfBrvjvziEA/xK5XWmxbabtLZDU8CZ3qhLi4F4YDP3u0DwfV4UC8TO45U+rkyt0gcd20TWCkQ5ONlDfBAoJvKbs0NmWquVRHLdzJwtpeki8XGeN37M4PJILsIpp+uK4QUHeoE/Lj/0arpOL31G3h3cwh1h8HDTecYRIDlrRbRqCECaD7gm13wgD0Csgl7VTSJA1ISQSlCjJAqQx0Jvo8LwhjCNzHCVUe6XqK1b72XQjP9dfMdcvixVM063Mx1TcFyJrobZVkMTn9MlfqTWtgrvLZdfgqa+kcW2BiuXCSXDsgG+k4mW+Fn/8g//RustM9pYw== Received: from MW2NAM12FT009.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::49) by MW2NAM12HT067.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::429) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25; Fri, 12 Feb 2021 05:14:43 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc65::4d) by MW2NAM12FT009.mail.protection.outlook.com (2a01:111:e400:fc65::76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25 via Frontend Transport; Fri, 12 Feb 2021 05:14:43 +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; Fri, 12 Feb 2021 05:14:43 +0000 To: PHP internals Thread-Topic: RFC: CachedIterable (rewindable, allows any key&repeating keys) Thread-Index: AQHXACLkMdQqZoaVtUy2vSZWXRDmOapT+fnG Date: Fri, 12 Feb 2021 05:14:43 +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:5945B721A8D1803220204D0BB2783DED041EB762714DA071DBC09338AFCB5319;UpperCasedChecksum:F83274669D9533CF652840F36CEB68F150AD4A6A9C5B453B9B87BD4030252940;SizeAsReceived:7077;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [cXAI6gBGuJ/L6Zl/PpuIBh8wl4p/zv5MaoACP1W7u3ByeaJ/rJu4FUYwqeYE9t4g] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: d9115637-7945-4c7b-2df7-08d8cf151b5d x-ms-traffictypediagnostic: MW2NAM12HT067: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: CAt02xWZyhdVm/mzL7OTBlfLvjvLHxHVyPp/nm2jGOlep9kzyHdMoaDHfzwumq6/IbdKlMJtX+kgWCXBi7/wrtEQmjPxAj/jlGkLUSqsFPqhClhgcau+Ra3LmkV+PtZ2nvZSma1XYnJgybtRX0AEWxvTTbH45VAEBq45yDZdIOVPx9Tga3XTfWUkc9fwBeajNcolZACSK2xed34B1nSZ6e8MEu5GS4vYlWuD3I5JHIicYnt2cZJlS0lshKnJ5/wIUq3H9jeZwCrDjMXne6LVgaUbxwY0S8+LA19QmdLK9Y9jCngSXxus8a6NTRKuZ9NQnRzV3jP2V7C415cwdHfJcPhIuihTkeMr6Ico9Uu/A9dWYgmsa6GpfGuu3wm0vFFrTlsbalB9CDXkz5Av/u0Rp3NWLvSR3xM5SNpROoEoh9RUgP6v/qCX7drH/zI5aOyQ x-ms-exchange-antispam-messagedata: ggTUw1BZBhMxL0kJHLwu707gc4DMF0ax4zOGgKVm2+R8c3oT/uFfopBnn0OPKkNQXHIq4QEbh9F68vdYlicAZhDRJ9sN1cmgshh+4cf8IcVTDBZc+1hXU04NzYCJvoVuHP2X2QPsyU5qHFlByn02WcKFxEd1Hi8KnKf6+dUJ582z4EOlPRbx0L0M3LoA2gN+9hYCuttHJnQ5dhhHjY9dfQ== 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: MW2NAM12FT009.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: d9115637-7945-4c7b-2df7-08d8cf151b5d X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Feb 2021 05:14:43.2539 (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: MW2NAM12HT067 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= > Any other feedback unrelated to namespaces?=0A= =0A= After feedback, I have decided to postpone the start of voting on this (or = other proposals related to SPL or iterables) until April at the earliest,= =0A= to avoid interfering with the ongoing SPL naming policy discussions.=0A= =0A= Thanks,=0A= - Tyson=0A=