Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114933 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80721 invoked from network); 17 Jun 2021 16:31:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Jun 2021 16:31:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 587FB1804B0 for ; Thu, 17 Jun 2021 09:48:32 -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 NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2070.outbound.protection.outlook.com [40.92.42.70]) (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, 17 Jun 2021 09:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kyaPDczDIZqUSBtr063EBruADy92lp1FDREgwRUWaGrCzDuCZyu666OYHmDU7GtsN/TZ63o1dMMb8/5efq07JvVhEWK+l2jFO0yPzUhLlUaYtAk0IAQcAg2O8l3Gr3Y02mv/tr9SHZhPJ4COcsJ1oPxNjr7LOFovgz2i75XbKloQW+S0fweCo2t7EYBstcTUBnHHCjfSNWyqL0lCzS56FYRZ3z6rDi7KcMKWq1tidzC2aE/4bE994DA6LKkLYNPa8T64d4HC2fnqcpzC6x94ZP37He+K99Softs+Bcu+Ym3sD/ZEI+K2DSk5HjYYeU8JW2/eCSNcq7WQwOw5j6h7aQ== 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=EYAq94+wHihL8V6FPIS+zcJLsNlGvJGYc+Qj12VxnaQ=; b=XIMyCZGCYz9Rv/aV5JlTs+Jccm+cRRGoIS5EXlkvePjL0h50rS3ABNW1/UFw1N+KCUMChYEamnsutJpk28so7ZSv/glNohugY5rzQtzbYG0XExuK7Lv+ntrzPLjTzV4GplVKURgjIv0vJISTCB0gsyilhS+zFVggmFrIrG2oZ+zMMWFjp9/HilQ7IqZh68JcF/s+oqoUleJwyHzcW+1Wnn1Zk41G4yl7TPy7/mCMTQ4b3YsDOdoFxwE9hbaEVdcm85fYQyDGFE66JC8RXywM/03i/rFN3tlU+HHb4GCxsXJZQmHxqqhJ0w9JlvTrReRVuMslsyzNTMpVwf8u+L/lBA== 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=EYAq94+wHihL8V6FPIS+zcJLsNlGvJGYc+Qj12VxnaQ=; b=B0vrwN0m3F5TCdCYOHuNplim/3zOEXw7ySc9kpUcTXwbvEXgSkAIdITF0rT+nyWYzasClK8X2Bvu/yFuuM0OyQTNrkqWEQJdtSGDoWxp4Hudg6vKuC6rI7kOl+6+JnzQKF0kD0YMpDaCQiVcl/fD6yqcTP/Q9ZSSU7SPdEsA2kqg40ZpuexLbvkyBdsWS/HaCuxgmhKeWrvP3Sqt1UADM8c6eM9fOtV80T1YkYMus6lSyuUTYOW62xbCVJIePVKtOZ8sTwRlKEiX9OTMxldW1ZCsf7Lsv5F/xSL6IQ51lzfVVfyA+h9Ww0uhDjajVIshZvjjGGQqQwPjOlNe9+VddQ== Received: from BN7NAM10FT012.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::45) by BN7NAM10HT116.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::462) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18; Thu, 17 Jun 2021 16:48:30 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e8f::47) by BN7NAM10FT012.mail.protection.outlook.com (2a01:111:e400:7e8f::114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18 via Frontend Transport; Thu, 17 Jun 2021 16:48:30 +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.4242.021; Thu, 17 Jun 2021 16:48:29 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] [VOTE] ImmutableIterable (immutable, rewindable, allows any key&repeating keys) Thread-Index: AQHXYe13gwPEOnQYu0+kS+xXdQPfpqsWWbeAgABMCZSAADs1AIABWyiAgAAwWLI= Date: Thu, 17 Jun 2021 16:48:29 +0000 Message-ID: References: ,<80e8d639-35ff-462b-a6b0-6a2decca8b96@www.fastmail.com> In-Reply-To: <80e8d639-35ff-462b-a6b0-6a2decca8b96@www.fastmail.com> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:63DA05D7DCC35AFBEB525831A63F7532DEC2316ABAD2338E44F8A1C049F87982;UpperCasedChecksum:0ED3C5EAB115BE567E007B74509BE89E0152EBCEBCD2B07ECFC8D78203B8C128;SizeAsReceived:7267;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Z8W1Rn9NZ0RgzJJSa9R9pW2+w7JUcv6s] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 44444f96-1bc6-4fa4-8f5a-08d931afbc54 x-ms-traffictypediagnostic: BN7NAM10HT116: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 09NJ3kxmJdGITOPCLdkXqOpnZdQPsT/cYn3EdIcwI8xsNPVdwNVpY0rdCZ/8aUXXLUlsShY6CEiCBEaJnbPHB+6+kHRiLh+NMpOcTxOzt6EkAmE5WKzBiDGiCCPZeZjHZMlsOjOzeic2MsfmR4lxM5pknnBmxJ0ff40FDXq+DExcbhsHoMwrrFQvhO0gm3Wbln1qNysFT8V4lRs7mivnRyS5S4noiWBgNlIYxMZ5Mx/fox446JlxTehzA//WThHaZeBJUVJWriui/iktjEjXygoooSWzzAfk26nmmt1WMfus8JiciAKOlvNmZ/AIZuz/2Hd2rxTgjHEWBOqPt5MHxdcZWhaUtsbzZIrBbbIVb5Xc9UTZevOgEWko4LrGrt8QXUDd5wksP+gO6IyKX65N9PldtQFfuRrlbz+Wsk+O+oO4gqBzaIW3jK/R3ErMp8TAu2a6xLFo+us1ROZ7fPxlZg== x-ms-exchange-antispam-messagedata: nL9qwBEtOSExjLKiW1RPg7+I/cw5dDur8BddwFH7WwQ1Pk+fLaFMaWiZJ6PDK08Bs/ytJH4UHbtv75VR4ZfsUe0wCM5zfckxGVl/rhLp1UtKqTSOFCHYplSKgApqem/0DhIdBJDTsZb8Knb67rmg/A== 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: BN7NAM10FT012.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 44444f96-1bc6-4fa4-8f5a-08d931afbc54 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2021 16:48:29.7622 (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: BN7NAM10HT116 Subject: Re: [PHP-DEV] [VOTE] ImmutableIterable (immutable, rewindable, allows any key&repeating keys) From: tysonandre775@hotmail.com (tyson andre) Hi Larry Garfield,=0A= =0A= Thanks for responding.=0A= =0A= > While I like the idea of an immutable collection, and the performance boo= st seems useful, this proposal seems to go about it in a sloppy way.=0A= > =0A= > 1) Iterable doesn't seem like the right "family" for this. It is iterabl= e, but so are lots of other things.=0A= =0A= I'd suggested alternative names such as ImmutableKeyValueSequence, in https= ://externals.io/message/114834#114834 , but=0A= =0A= - It seemed as if the sentiment was very strongly against long names. I lik= ely misjudged this.=0A= - Many names were suggested by only one person. I can't tell if there's a c= onsensus from that. E.g. `*Aggregate`.=0A= - When I suggested names such as `ImmutableKeyValueSequence` before startin= g the vote, nobody had any feedback of it being better/worse than my previo= us proposals.=0A= =0A= > 2) I... have never seen anyone in PHP use "pairs" as a concept. I have n= o idea what they're doing here.=0A= =0A= https://www.php.net/manual/en/class.ds-pair.php is a concept used in the DS= PECL, e.g. https://www.php.net/manual/en/ds-map.first.php=0A= Proposing that as a new object type seemed excessive here.=0A= =0A= That reason is because PHP is (fairly) unique among languages with generic = iterable types in that there's a key associated with values.=0A= I had to deal with this unusual situation somehow, and it's not a surprise = that the solution is also unusual.=0A= Do you propose alternate solutions other than omitting the functionality?= =0A= =0A= - Javascript only provides values in .next() - https://developer.mozilla.or= g/en-US/docs/Web/JavaScript/Reference/Iteration_protocols=0A= - Python only provides values https://docs.python.org/3/glossary.html#term-= iterable=0A= - C++ iterators only provide values https://www.cplusplus.com/reference/ite= rator/=0A= - And so on=0A= =0A= A generator-based workaround would be much slower=0A= =0A= ```=0A= function userland create_iterable(iterable $pairs) {=0A= foreach ($pairs as [$key, $value]) {=0A= yield $key =3D> $value;=0A= }=0A= }=0A= // $pairs =3D array_map(...array_filter(...fetchOrComputeData(...)...)=0A= $iterator =3D new ImmutableKeyValueSequence($pairs);=0A= ```=0A= =0A= The other reason is that php has a large collection of internal and user-de= fined functions for dealing with arrays (sorting, filtering, etc), but few = for iterables.=0A= toPairs and fromPairs allow easily converting values to this and back, then= calling usort/filter for compact code.=0A= =0A= And if I provided fromPairs, toPairs seemed to make sense for completeness.= =0A= =0A= > 3) The JsonSerialize seems out of place. It may make sense from another = angle, but it just sorta appears out of nowhere here.=0A= > =0A= > It almost feels like what you actually want is an immutable Dictionary cl= ass. Such would naturally be iterable, countable, serializing makes some s= ense, a fromIterable() method would make sense, etc. =0A= =0A= It would be useful for some but not all use cases. Especially use cases whe= re keys aren't hashable, or where keys are repeated.=0A= =0A= Not all values would be hashable in a dictionary (e.g. circular data struct= ures, self-referential arrays). =0A= =0A= There's a lot of open design questions for Dictionary in core, e.g. the nam= e, and whether objects should be hashable, or namespace, or whether it may = conflict with future native types.=0A= - And if a Hashable magic method or interface was added, then that might th= row and make it impossible to store a generator.=0A= - And if large data structures are used (e.g. yielding extremely large keys= or slow object hashing, the hashing would be slow even when the applicatio= n didn't need hashing at all)=0A= =0A= > That I could get behind, potentially, although it also runs into the exci= ting question of type restrictions and thus generics, which is where list t= ype discussions go to die. :-)=0A= =0A= That's another possible obstacle to dictionary in core, but I hope not.=0A= =0A= Thanks,=0A= Tyson=0A=