On Wed, Jun 2, 2021, at 5:59 PM, Mike Schinkel wrote: > > On Jun 2, 2021, at 4:25 AM, Jordi Boggiano <j.boggi...@seld.be> 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php