Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123074 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 23B6F1A009C for ; Tue, 9 Apr 2024 22:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712700814; bh=cFI9f2R2F0wWHte5bhmoxrtMJU6tlbtDYGBm/akIvfI=; h=In-Reply-To:References:Date:From:To:Subject:From; b=HvDYGl5K5LDtTEy5z+D82Hx9FrGwPHD6i8qpRfsuSTF4jGA01Sdc2DfwH7ksnhUGb 7kdlgFtYPvMqnQzaUpjbD95H4Ge/Lff6QSvdqsWfT8MOwQtwWYtMVJV8XleXuFTkno YVlIEyeiOuSmYUrOVkQ9vZ23u1pvZRzmR+Bcb4Wcc8gqqK3wH4zkBttUYyik4t+D+V zJ5/quvvHnX1grlgReGPFgEfvaXTyWXGTMYVU2v2gVguXyqpho3079Ka4Nf0CVKe+y vB/VqDf3TskynLK0R2serYbcD5neHNhakRBauxWee0OYJJpd5ScFKaF9CmsvyOU6wY 7BYdWj9rtDuYg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BCED18007C for ; Tue, 9 Apr 2024 22:13:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 9 Apr 2024 22:13:32 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 9A42013802A9 for ; Tue, 9 Apr 2024 18:12:59 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 09 Apr 2024 18:12:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1712700779; x=1712787179; bh=BGvCALOPOekYB9JYHWsE8 FNONO02fESwLnz11mo4fBs=; b=OV9f+iohGBHhnutuMdw8mf/ZJhb0jcRojusHK qaMV0vzX/0ycRGe2/2DW5lIkPSWsRu1rIZcLeBpw17f88LRWbpLfXLhGhlFQ+HSp oKcMx0DyuSijuM5BTMOVaQ6c+EbOofWJyXDboIJY1vFld1qG6NSBe6kWhV/fMYzO 7AMp8jeeeJI/qpGvfWH8gxKRIaYXmunYHjwdCndphm6TAW/UxNL8qSq4dFeBKhs8 o5VvvZ+7pOGCLM+4QhsxyoqOm6h2da26U8Xf88OpYnLaFRczvQRBUKe/kxnFw5R1 ZPFr384om+FGEQBAgWOkmNa+AW+3SMqlaJoLq4qBoOqhCpAmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712700779; x= 1712787179; bh=BGvCALOPOekYB9JYHWsE8FNONO02fESwLnz11mo4fBs=; b=k A3TF/31vNfsUD7yjgIwA5z+Vgl/n/nCVg2qrTFDlHAWflfLyjhl9ToCrqKi8Waj6 8mmudErfDf1JI4hOVz4R2/6I5NgJduTZlI+4ku55fSZw3VYgsIN3ZsLA+2gCDVB6 MYjdd3x0RGvygASNl91O8prBxAk5gwasMUTfiM18dhZ9Gp7xRuLwBANQSHHPO0/X RBWVLaD+UwTn00IG/Pwdi2LaEKrcNXCzjJApTKWJlAP1KJYSMLGvvnkO1bs0AxlV fq1ummoAb3VTjkBMy7FpZpt6c5uyQEaop5ZsqwNn/N3AJTEBPjfdPRi/diUj/Gn2 3WUmETE3Sl00XeEdErvvg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehhedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1F8E11700093; Tue, 9 Apr 2024 18:12:59 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-379-gabd37849b7-fm-20240408.001-gabd37849 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <2dd7ef64-d1c5-4ed8-964f-b86dba110e0d@app.fastmail.com> In-Reply-To: References: <24e4529d-0b75-44de-90ef-34de5dfb1c99@wcflabs.de> <278889be-82ab-4827-a9e7-801b5ba2d8f8@app.fastmail.com> <45b726f4-8085-43e2-b701-6b35bc249409@wcflabs.de> Date: Tue, 09 Apr 2024 22:12:38 +0000 To: "php internals" Subject: Re: [PHP-DEV] RFC [Discussion]: array_find Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Apr 9, 2024, at 7:49 PM, Tim D=C3=BCsterhus wrote: > However I'm not sure if adding new array functions piecemeal is the=20 > right choice at this point. array_any and array_every are conceptually=20 > very similar to array_find and are missing as well. In fact=20 > array_any($cb, $array) =3D array_find($cb, $array, true) !=3D=3D null = and=20 > array_every($cb, $array) =3D !array_any($negatedCb, $array), but it wo= uld=20 > make sense to have them explicitly for clarity of the reader of the co= de. We're in a major catch-22, unfortunately. We know that collections/iter= ables are long overdue for a rethink, which means small fixes are just m= aking more work for the future. Intermediate concepts like the pipe ope= rator have been rejected. However, a full rethink is a massive undertak= ing, and few people want to do that given the entirely unknown odds any = RFC has. And a *real* rethink doesn't make sense to do without generics= , and... yeah. So I genuinely don't know what to do here, strategically. >>> 2. Key handling. It's good that you have looked into this, because = I was going to mention it. :-) However, I don't think a boolean is the = right answer, since the question is binary, not true/false. (Those are = not the same thing.) I think a small return-mode Enum would make more s= ense here. >>=20 >> I like the idea, thank you! However, I am unsure whether an additional >> enum for the function would not be too much overhead. > > I feel the same. Adding an enum for each binary parameter that is=20 > semantically true and false feels quite unwieldy with how class / enum= s=20 > / interfaces are currently organized in the namespace hierarchy. Point of order: This parameter is *not* semantically true and false. It= is semantically either/or, and we kinda twist sideways to make it look = like true/false if we squint. That's actually pretty common in the curr= ent stdlib, though it's not a good approach. Hence why I asked about an= enum. I wouldn't expect it to be single-function, though, but to be ap= plicable for multiple functions. (I did not go looking to see if such f= unctions exist.) > Some of the array functions have paired function with a _key suffix, b= ut=20 > looking at the docs it appears the difference usually is that they=20 > *operate* on the keys, instead of returning the keys. So I'm not sure=20 > whether adding a array_find_key companion would be confusing or not. Another alternative is to always return the key, because you can trivial= ly get the value from the key, but not vice versa. Of course, the resul= ting syntax for that is frequently fugly. $val =3D $array[array_find($db, $array)] ?? some-default; I don't have a good small-scale solution. --Larry Garfield