Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125826 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 064431A00BD for ; Mon, 21 Oct 2024 16:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729528294; bh=aECEu0vPGDvLNzhDfWmFtnlskn9mJshBAyXOQ5sO3Q4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MmD9qiEOUXCD7ZFHKCsPjj14DAFU5T1RiKDM8elBL1CqOS2Zegm2VdgwV/OTwDEbp 0ld7mBj4CsGsA1uRCZ1c+nyekmS4KoFdburrl4SKdm27ktT1X0CZ03gEk8WJaDm5aP X1hTMAxhKq/TK0XSNnZmdg7WdVO19+5m8HIavDyY+MGcWHntuVgLMJNYf8pvcVT7Ew BC4f0tRvEHeXIjXf9XjD3txz5LVTiHg6VsWbF+J4lnRUCy6IjGJzfDFhxZRGLM9p29 RRKhV8i31DHGha10yUnPLGCrFmF7G3geg75Z9Jbdq7A4TF6z3G6C8DXifkfZWIG/Sl Na39xok3A6fqg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B1A7718006F for ; Mon, 21 Oct 2024 16:31: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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 ; Mon, 21 Oct 2024 16:31:33 +0000 (UTC) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43169902057so22586135e9.0 for ; Mon, 21 Oct 2024 09:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729528148; x=1730132948; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aECEu0vPGDvLNzhDfWmFtnlskn9mJshBAyXOQ5sO3Q4=; b=bOF76Md9cNKD1Vs+aQRUdgzwG2scdvKskruk5ogusSoIAVYaPMPz8ZS90sWUTe9C7K NPktzHd4NIrqwH3+hNQ/f9BzhBdcSZz0OJ2sR1+CcJ3kcc/R/8XRliBQIGjOskWxbxt0 /RPg5zF28AmFTplY06hofUgEAFgZqd8o9CoLLq0WyPxEU5cb1s3wEAiHp1Qw5uPCFWF/ K/d9Qo/fBfjzuqm5hFdYb1+kXQdW4WaeW8t78OSUnLXJU9/UlF38Q1/3JO6/2Jl+joxE IvaJHAMQmO6NdQEbFEViMo5KyM9AZB0L6Hp4ckMuputlKf96W7V5QR7EljyLRungFz9m 0uLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729528148; x=1730132948; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aECEu0vPGDvLNzhDfWmFtnlskn9mJshBAyXOQ5sO3Q4=; b=P/IN2uBDWE6al8z0y6Rdvz3tzK/lGNCmLtK7vsxNB9/0EM11ATLP/5fMAEyv6fZ5JA ctmnm9HIklbohoqHTNavQwCuLQ0voBSybh5a987zvi/GrsA/Rzt+xWlIfJjMXAXSl6t7 Hb2JVXb7J2Ub1tUdGLESggBneU7fs0Y9Io4p31JEsFLFHFRXFDOwRSX/9AFPaCLgoRdk JjX8aZG5IAHQHsFRtD7zozPg1woINeZY9b06w+gd41tVQHzzgea/oML91hBpTMv9JyKR hivMDo5Xd9DLHqurDW4b47yPmXf0o0HWSPkfNOvFp50RggZpO0qcm2xcni0mUrf3NOpK b9sA== X-Forwarded-Encrypted: i=1; AJvYcCXV8y9pCFeMR0Aal66NcsXhDw4wceWLtXlsm8I6LmDmtOsIKlJYICzx2yCOuwNrBiNPR5Wqb5KfIkI=@lists.php.net X-Gm-Message-State: AOJu0YxvXAWsv3wZjj5f6KQYtY9w7Tx7WD+9N+CWb3M3CnW2RFn3zCBh GFUKWL0j5xYktXxKDdGfV7CvmC7OI2ravRVhZJF2Iz9NRyNCwH5BMOQdij+F1w652uC9JYnTnJ+ 5e5CBI43uSuklLAjcurh/zrSlww== X-Google-Smtp-Source: AGHT+IG9IdZavivOF94Fpeja/iBAqlDjaCU6DdIiYi5sPYnVCv1NMugipEqAlbxyuCSFQhxaOgcZGFmQJ7JGw7PEtns= X-Received: by 2002:a05:600c:3d18:b0:431:5459:33c2 with SMTP id 5b1f17b1804b1-4317b8edc66mr5377405e9.17.1729528147891; Mon, 21 Oct 2024 09:29:07 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 21 Oct 2024 19:28:56 +0300 Message-ID: Subject: Re: [PHP-DEV] [RFC] Change behaviour of array sort functions to return a copy of the sorted array To: "Gina P. Banyard" Cc: Ilija Tovilo , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: udaltsov.valentin@gmail.com (Valentin Udaltsov) On Mon, 21 October 2024=E2=80=AF=D0=B3. at 18:13, Gina P. Banyard wrote: > > On Monday, 21 October 2024 at 14:29, Ilija Tovilo wrote: > > > Hi Gina > > > > On Mon, Oct 21, 2024 at 3:21=E2=80=AFPM Gina P. Banyard internals@gpb.m= oe wrote: > > > > > On Sunday, 20 October 2024 at 18:42, Gina P. Banyard internals@gpb.mo= e wrote: > > > > > > > https://wiki.php.net/rfc/array-sort-return-array > > > > > > For an example, I'm going to pull out my solution to day 1 of the 202= 2 advents of code: > > > > > > https://github.com/Girgias/advent-of-code/blob/19283e1f5ef503c8a4478e= 58aaa57ff2fb7164c7/2022/01/puzzle.php#L25 > > > > > > However, if the sort functions would return a useful value instead of= `true` I could chain it together completely as follows: > > > > > > $top3 =3D array_slice( > > > rsort( > > > array_map( > > > 'array_sum', > > > array_map( > > > fn($v) =3D> explode("\n", $v), > > > explode( > > > "\n\n", > > > $input > > > ) > > > ) > > > ) > > > ), > > > 0, > > > length: 3 > > > ); > > > > > > Note that your example would still warn after this RFC, which is > > likely enough to deter people from writing code like this. > > > > https://3v4l.org/mRuoK > > There is a very simple fix, which is to add the /** @prefer-ref $array */= doc comment to the stub of the relevant functions. > Something that array_multisort() already does. > But thanks for reminding me how crap PHP references are :D > > I'll amend the RFC soon to include this change as part of the proposal. > > Best regards, > > Gina P. Banyard Hi, Gina! What if instead of this proposal we reimplement all of the array functions in a different namespace and fix a lot of other problems and inconsistencies? Array\map(iterable $iterable, callable $mapper): array Array\sort(iterable $iterable, int $flags =3D SORT_REGULAR): array ... --=20 Valentin