Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113028 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60508 invoked from network); 31 Jan 2021 00:54:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Jan 2021 00:54:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A9A11804F6 for ; Sat, 30 Jan 2021 16:37:03 -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.8 required=5.0 tests=BAYES_50,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 NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2067.outbound.protection.outlook.com [40.92.42.67]) (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 ; Sat, 30 Jan 2021 16:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jkroeb1OPSAkCSI2AKwwq3e4nBZI+mffzDrP980JJ1JF/otX0MBGH+LTUSJhZZ3iwlmBAjRuDaU7cZD+0T9orMfD0PuTYJ3TKvt0DDqZgghVxhH+/q/BYv/zKJ+3lTAA/f9gHB0ew2xWjYnx4rB1QQFdR9red9skmIDD6pX51J3qnhnI1+gnLmyXjG7RcESzMrVttJ3VuEh28h3him4u52x2mjKGciNffJiM4A+wibm1ynYNrQGMQBbLS5OXF87WHeCBaXUIjSANGMOedVKsLQ8UXLAReHaYRt4xhRmvKCNPCo4J+KJN6EmmiuReBKA4IInoPOF7djB0fvX4ME65HQ== 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=XmC4K28fmnSEdHA+PFyGiX0VyU9nCLFl3TtKakr1Ab4=; b=DmslFA2uN8Y3RUY4M/YM8tvwSNKYyBmu2ofhgbiFslrDpBwRVvr5HeOuafudVf6CuY+oAR0nkr7EQ+aTigLGhQnRSJqiNEvfjFBZyIIUDklI96iCW8ntz9i7JhJDiWe3uX3G5ruthZ2leopswv4im3EDgOg+u8zxbfNyYHeBXazBNy30hCMIosNqHj+IcPeMf3fEyeI7stL6iJkWD6/yspc4/3gnUk7A0zO8WJoawe77cIPviFe9KhNzv6dETSMK4oi1p8WjqvHw7Pm83MGWhLPV8Cbt804vgkeDcub6t8oSOmu/SPxJkGMAMJMYPgZFQkRbna9/xnI/QPq4UT7jZQ== 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=XmC4K28fmnSEdHA+PFyGiX0VyU9nCLFl3TtKakr1Ab4=; b=nqMAlKkXzjSWbVOm8NQFJSSuOBMmnn9I4T9xDy6nL3nNNqH5yxPjuZoYM0eaTQOu/HFr5QmDvjL2xvPExfgxtqdVFyo+tbP5JSPa2yS678LB7UXWB3EOe/yUrFYo7GHAOBW27Hv/f44qQkpZLj2mxZDWYAFCovF+EGTGPDLNHRpTqWs925VufuNEDyJP2NAv4p5uc9Vn4968oXKX3vn6kLGqHQ6coRiBlhMPHS34I+/yYaMPg8j2U0nuUak3p+mkM4C+a6dN8MqqtwIgLsV6Wlzc2FwzZ2uXrMU2ZWbhUhI7I0gV0/FDThXr5jH1L5aLsgDfvuSQ0udlnq01yQSgMA== Received: from MW2NAM10FT050.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::49) by MW2NAM10HT015.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Sun, 31 Jan 2021 00:37:00 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e87::48) by MW2NAM10FT050.mail.protection.outlook.com (2a01:111:e400:7e87::269) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Sun, 31 Jan 2021 00:37:00 +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.3805.017; Sun, 31 Jan 2021 00:37:00 +0000 To: "internals@lists.php.net" Thread-Topic: Proposal: Adding a RewindableKeyValueIterator type allowing mixed/repeated keys Thread-Index: AQHW92K4Q7dSQ8CfzUK9YysQDgaLrg== Date: Sun, 31 Jan 2021 00:36:59 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:B6DBFA6F9BE3726316F980103C33B05DC8865C4DFB9943C355CB8071B0FCDC63;UpperCasedChecksum:A7666FB244744D844C31DBFE7ED51447DC97C834D77795B558CB9FE2FFF71C4F;SizeAsReceived:6894;Count:41 x-tmn: [X+4Rn3FY05EmsCQEmHPMcFTmO5a4SeKxuKlJxrWZVgG4P3enhaEyvVLgSQ4r5VEa] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 32680e4a-b308-4401-b816-08d8c5805263 x-ms-traffictypediagnostic: MW2NAM10HT015: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: X+y1mqatU+TZxhKLUEvDjSoCFYQhRWC++/cgxkXDfzs/fSYkjttMuFBKZpM5F1MwrzetKk6jOF3Yr9kOfPtDlktDOnirCjB3jfyUfsKh4eqDGfmx8P609g6e6rtcI353bBZZ0VS6PcaIjRKjOxPyJ3oFV+6FQfVF2j3e6QG59uPK7Q7bkfKqVieHCN2rHD1Aut1MKvFDLeuoS5/MGP/bKdXh2eBcLgfQ16LhFlCr9ggCe5GuthPT1OokfYvzL0R7M3u6Oqf7o85c3EHVEaq++OV8Mg4CTGJ4n8x799Unex2vp+aKuq9gNaY6LDFBVG8I205/UqzTFhqupOs5iRNLP8dAAqoHTVio/quE5aOeeanlPb9FJMwl/u1IT5z5Zteo2Kvqf0k/2I5J/tVuNI9Ti2mqSf0auVqIhfZfMfyroZg= x-ms-exchange-antispam-messagedata: rE5yjoMb6/SifGJWzGxvtt27z4D0lbvsyXnWMio/AdRyeHzSSuupMqIZpnGDcN1BV8e6x5w/J9z6sQ5E3Kv+e9cLUe2V3rFLWZljMhNUF1xSTS60TvJlfZ5TqTjdcrXro3O98qnz06+yT762e827wg7C/IDLZoCyBU5tArhPa+T2nDD+ZQdCQTp3Dzn9rj+SHpAaXbQ827l4I2MgiDfhJQ== 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: MW2NAM10FT050.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 32680e4a-b308-4401-b816-08d8c5805263 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jan 2021 00:37:00.0638 (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: MW2NAM10HT015 Subject: Proposal: Adding a RewindableKeyValueIterator type allowing mixed/repeated keys From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= Currently, there don't seem to be any internal classes that can be used to = store a copy of the keys and values of an arbitrary Traversable.=0A= =0A= -=A0This would help in eagerly evaluating the result of a generator in a me= mory efficient way that could be exactly stored and reused =0A= e.g. `return $this->cachedResults ??=3D new \RewindableKeyValueIterator($= this->innerResultsGenerator());`=0A= https://externals.io/message/108767#108797=0A= - This would be useful to exactly represent the keys of sequences with repe= ated keys (e.g. `yield 'first'; yield 'second';` implicitly uses the key `0= ` twice.)=0A= - This would be convenient to have to differentiate between 1, '1', and tru= e.=0A= - This would be useful if php were to add internal global functions that ac= t on iterables and return Traversables with potentially repeated keys based= on those iterables,=0A= e.g. map(), filter(), take(), flip(), etc=0A= - If PHP were to add more iterable methods, being able to save an immutable= copy of a traversable's result would be useful for end users.=0A= - If PHP were to add a Map (ordered hash map with null/any scalar/arrays/ob= jects as keys) class type in the future,=0A= and that implemented IteratorAggregate, the return type of getIterator() = would need something like RewindableKeyValueIterator.=0A= - The lack of a relevant datatype is among the reasons why classes such as = SplObjectStorage are still an Iterator instead of an IteratorAggregate. (an= d backwards compatibility)=0A= =0A= ```=0A= final class KeyValueSequenceIterator implements Iterator {=0A= // loop over all values in $values and store a copy, converting=0A= // references in top-level array values to non-references=0A= public function __construct(iterable $values) {...}=0A= public static function fromKeyValuePairs(iterable $entries): self {...}= // fromKeyValuePairs([[$key1, $value1]])=0A= public function rewind(): void {...}=0A= public function next(): void {...}=0A= public function current(): mixed {...}=0A= public function key(): mixed {...}=0A= public function valid(): bool {...}=0A= // and __debugInfo, __clone(), etc.=0A= }=0A= ```=0A= =0A= Thanks,=0A= - Tyson=