Redefine spread to use iteration? (Was: Set constructor arguments)

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Feb 14 13:13:21 PST 2012


On Feb 13, 2012, at 1:20 AM, Axel Rauschmayer wrote:

> True. Assuming that the spread operator works on any iterable,

Not as currently specified.  It does the same 0 to length generic property enumeration as is used within the "Array extra" functions.  Changing to using an iterator probably would be possible, but we need to consider all the implications.  For example, I would expect 

   [...firstPart, ...secondPart]

to be somewhat more expense if spread uses iterators rather than as currently defined.  Is this extra cost justifiable in light of the most common use cases? Maybe, but I'm not totally sure?  I think implementors know how to easily optimize the "array" accesses used in the current definition of spread.  On first consideration, optimizing an iterator based loop seems fundamentally harder. 

Allen





More information about the es-discuss mailing list