On Wed, Apr 22, 2020, at 1:49 PM, Matthew Brown wrote:
> > Is it an effective subtype of array?
> 
> I was thinking it should be (with the auto-conversion mentioned above), but
> I can see a compelling case to not have the auto-conversion when
> manipulating – while it would bloat the stdlib a little (we'd need a whole
> bunch of list_* functions) the separation would simplify things a lot (e.g.
> list_filter would return a list with sequential keys, whereas array_filter
> returns an array with possibly non-sequential keys)
> 
> And then you could cast between the two like "(list) $some_array" (which
> would preserve order but remove keys) and "(array) $some_list" as
> necessary. There could even be some automatic list <-> array casting when
> calling functions not in strict_types mode.
> 
> > Should they pass like arrays or like objects
> 
> Definitely like arrays – I want them to be a drop-in-replacement for people
> who currently use arrays in places lists are more appropriate.
> 
> > Should they be mutable or immutable
> 
> Definitely mutable, like arrays are

That has a long list of possible issues with it relating to spooky action at a 
distance, depending on the passing semantics.  In some languages lists are 
immutable, and with PHP's copy-on-write it may make more sense to just go 
immutable.

> > Are they iterable
> 
> Yes, the keys are sequential integers
> 
> > Does it make sense to add them without type enforcement via generics
> 
> Absolutely – this shouldn't be tied to generics landing (which I'd imagine
> is a PHP 9 feature at this point, whereas this could be a PHP 8.x feature).
> 
> > can they be mapped/filtered/reduced
> 
> Absolutely – I think we'd have list_map, list_filter, list_reduce functions
> to provide that functionality.

Why duplicate all of them?  Rather, map/filter/reduce need to be recast to work 
on any iterable, which would then include lists.  Or, if lists are an object 
they would be methods on the object.

Hence my point.  Lists would only make sense if we're also rethinking how 
collections work generally, for which we're already overdue.  Just tossing them 
in as yet-another-different-thing would make the situation worse, not better.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to