Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114699 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2665 invoked from network); 2 Jun 2021 22:54:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jun 2021 22:54:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 623D61804AE for ; Wed, 2 Jun 2021 16:07:52 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 2 Jun 2021 16:07:51 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 893FAD5A for ; Wed, 2 Jun 2021 19:07:50 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Wed, 02 Jun 2021 19:07:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=IopJe4 I5qtJrLnQkOWzK98qOOgRHJycOYsue0BOhWJc=; b=FXZtlOOc2f61p+1vrQV/1b Xhtu3RMZmKVyWb6Y+oycv2VJ7n0xLrezEjpsjG3DDG87BkKE6P0IRy6RpZG4tMR6 CIk/3XAi1y7MbLLuKwJG2ElFkJRHYTN9VWzrYeikRaNJ2KzpiSzKPzZbDlGBYPSG 0uMdVC38pIwHWnelcfB+vrcBP4n9tcJ5TdFllU+7ucjVGhE6qV0du3GjEa5hmy0v j7+jgXL1MF6QVdpKvxyaJ9AN8qFwgoDlDgsYFRdRqhSSTxECdG6B484JgkxsmDCu 7T3AQOgV732U8YMEh41ojr/FF0FzljBhUFv0A2u/R8DL4AtSGCOP7kjk3/LaXIbA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdelkedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A4A98AC005F; Wed, 2 Jun 2021 19:07:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-519-g27a961944e-fm-20210531.001-g27a96194 Mime-Version: 1.0 Message-ID: <0857bb8b-456f-41d3-9a51-35f9ab629e61@www.fastmail.com> In-Reply-To: <761D99C1-4728-4EE8-95F8-44A240AE1473@newclarity.net> References: <761D99C1-4728-4EE8-95F8-44A240AE1473@newclarity.net> Date: Wed, 02 Jun 2021 18:07:29 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Regarding array_shift()/array_unshift() From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jun 2, 2021, at 5:59 PM, Mike Schinkel wrote: > > On Jun 2, 2021, at 4:25 AM, Jordi Boggiano wrote: > > IMO for unshift() it'd be fine to return a new array, but when processing a list of things in a FIFO pattern I often used array_shift() to get the first "job" out of the array. If $array->shift() returns a new array then how do I access the first item? > > That is a really excellent point, something I did not think to consider > given how rarely I use array_shift(). > > But your comment causes me to ponder a number of follow up questions, > some of which are tangential. If any reader feels these tangents are > worth discussing please make another email and quote my relevant > comments so we can have a dedicated thread for each. > > 1.) Given Nikita's position that it would only be viable to offer a > syntax that simulates method calling for arrays if the methods > themselves are immutable can you envision a solution for allowing > $array->shift() functionality that would address getting both element > and shifted array without resorting to by-reference parameters? $list->head() (returns first item) $list->tail() (returns all items but the first one) Straight outa FP. :-) Can probably do some internal optimizations to make them more efficient, but now we're back to the discussion of a List or Vector type built in, which always runs into the Generics discussion, so... yeah. --Larry Garfield