Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread T.J. Crowder
We have two threads going on this with the same (and differeing)
points being raised in both, let's pick it up in the better-named
["Array.prototype.append?"
thread](https://esdiscuss.org/topic/array-prototype-append).

-- T.J. Crowder
Farsight Software Ltd | 20-22 Wenlock Road, London N1 7GU | Company #8393428

tj.crow...@farsightsoftware.com | Office: +44 (0)20 3034 0132 -
Mobile: +44 (0)7717 842 414



If you've received this message in error, please let us know by
forwarding it to i...@farsightsoftware.com and then delete it from
your system. Please don't copy it or disclose its contents to anyone.
Separately, note that email sent over the internet without a digital
signature may be modified en route.


On Wed, May 23, 2018 at 10:15 PM, Andrea Giammarchi
 wrote:
> Just one thought ...
> ```js
> Object.defineProperty(Array.prototype, "append", {
> value(...sources) {
> this.push(...[...sources]);
> return this;
> },
> writable: true,
> configurable: true
> });
> ```
>
> ... but also another one ...
> ```js
> (array.push(...sources), array)
> ```
>
> it seems to little of an improvement to become new Array method, I am
> already confused with includes and contains that append and push, when Sets
> have add, might cause me unnecessary headaches.
>
> Regards
>
>
>
> On Wed, May 23, 2018 at 10:14 PM, Tab Atkins Jr. 
> wrote:
>>
>> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband  wrote:
>> > `array.push(...sources)`, not sure why we'd need "append".
>>
>> From the original email (a bit buried and hard to find due to broken
>> threading, admittedly):
>>
>> > Has anyone ever suggested Array.prototype.append as an
>> > Array.prototype.push which returns the array itself?
>>
>> The point is x.append(y) returning x, whereas x.push(y) returns y.
>>
>> ~TJ
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Andrea Giammarchi
Just one thought ...
```js
Object.defineProperty(Array.prototype, "append", {
value(...sources) {
this.push(...[...sources]);
return this;
},
writable: true,
configurable: true
});
```

... but also another one ...
```js
(array.push(...sources), array)
```

it seems to little of an improvement to become new Array method, I am
already confused with includes and contains that append and push, when Sets
have add, might cause me unnecessary headaches.

Regards



On Wed, May 23, 2018 at 10:14 PM, Tab Atkins Jr. 
wrote:

> On Wed, May 23, 2018 at 1:05 PM, Jordan Harband  wrote:
> > `array.push(...sources)`, not sure why we'd need "append".
>
> From the original email (a bit buried and hard to find due to broken
> threading, admittedly):
>
> > Has anyone ever suggested Array.prototype.append as an
> Array.prototype.push which returns the array itself?
>
> The point is x.append(y) returning x, whereas x.push(y) returns y.
>
> ~TJ
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Tab Atkins Jr.
On Wed, May 23, 2018 at 1:05 PM, Jordan Harband  wrote:
> `array.push(...sources)`, not sure why we'd need "append".

>From the original email (a bit buried and hard to find due to broken
threading, admittedly):

> Has anyone ever suggested Array.prototype.append as an Array.prototype.push 
> which returns the array itself?

The point is x.append(y) returning x, whereas x.push(y) returns y.

~TJ
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Jordan Harband
`array.push(...sources)`, not sure why we'd need "append".

On Wed, May 23, 2018 at 1:25 PM, T.J. Crowder <
tj.crow...@farsightsoftware.com> wrote:

> On Wed, May 23, 2018 at 5:56 PM, Alexander Lichter  wrote:
> > An optimization would be great because in comparison to the existing
> concat
> > method, rest/spread is significantly slower at the moment (see
> > https://jsperf.com/single-array-composition)
>
> There's a limit to how much optimization can address the fact that
> `[...original, ...additions]` has to create a new array. And creating the
> array is significant, as we can see in the difference between `concat` and
> `push`: https://jsperf.com/concat-vs-push-number-42
>
> I've often wanted an `Array.prototype.append` (often enough I've been
> known to add it on occasion; obviously only in app/page code, not in lib
> code). It would be a good addition in my view. I tend to suspect the name
> isn't web-safe, though. So that would need investigation and design.
>
> The polyfill is trivial:
>
> ```js
> Object.defineProperty(Array.prototype, "append", {
> value: function(...sources) {
> for (let o = 0, olen = sources.length; o < olen; ++o) {
> const source = sources[o];
> for (let i = 0, ilen = source.length; i < ilen; ++i) {
> this.push(source[i]);
> }
> }
> return this;
> },
> writable: true,
> configurable: true
> });
> ```
>
> I've avoided iterators and such as a first pass at optimization (and it
> seems to do okay: https://jsperf.com/push-vs-append-number-42/1). Didn't
> use `push.apply` because of the limits it has on it in some
> implementations. This version assumes all entries are array-like and should
> have their entries added to the array on which it's called. There are a lot
> of other designs one could make, though. Just one argument (you can always
> chain); a flattening version; etc., etc.
>
> -- T.J. Crowder
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread T.J. Crowder
On Wed, May 23, 2018 at 5:56 PM, Alexander Lichter  wrote:
> An optimization would be great because in comparison to the existing
concat
> method, rest/spread is significantly slower at the moment (see
> https://jsperf.com/single-array-composition)

There's a limit to how much optimization can address the fact that
`[...original, ...additions]` has to create a new array. And creating the
array is significant, as we can see in the difference between `concat` and
`push`: https://jsperf.com/concat-vs-push-number-42

I've often wanted an `Array.prototype.append` (often enough I've been known
to add it on occasion; obviously only in app/page code, not in lib code). It
would be a good addition in my view. I tend to suspect the name isn't
web-safe, though. So that would need investigation and design.

The polyfill is trivial:

```js
Object.defineProperty(Array.prototype, "append", {
value: function(...sources) {
for (let o = 0, olen = sources.length; o < olen; ++o) {
const source = sources[o];
for (let i = 0, ilen = source.length; i < ilen; ++i) {
this.push(source[i]);
}
}
return this;
},
writable: true,
configurable: true
});
```

I've avoided iterators and such as a first pass at optimization (and it
seems to do okay: https://jsperf.com/push-vs-append-number-42/1). Didn't
use `push.apply` because of the limits it has on it in some
implementations. This version assumes all entries are array-like and should
have their entries added to the array on which it's called. There are a lot
of other designs one could make, though. Just one argument (you can always
chain); a flattening version; etc., etc.

-- T.J. Crowder
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Alexander Lichter
An optimization would be great because in comparison to the existing 
concat method, rest/spread is significantly slower at the moment (see 
https://jsperf.com/single-array-composition)



On 23.05.2018 18:34, Ben Fletcher wrote:
Does the `[...oldArr, ...elementsToPushArr]` pattern take care of that 
for you? I've always assumed it's much less performant than your form 
would be, but I (naively) suppose the implementation could be 
optimized like anything else


On Wed, May 23, 2018 at 8:01 AM > wrote:


Send es-discuss mailing list submissions to
es-discuss@mozilla.org 

To subscribe or unsubscribe via the World Wide Web, visit
https://mail.mozilla.org/listinfo/es-discuss
or, via email, send a message with subject or body 'help' to
es-discuss-requ...@mozilla.org 

You can reach the person managing the list at
es-discuss-ow...@mozilla.org 

When replying, please edit your Subject line so it is more specific
than "Re: Contents of es-discuss digest..."
Today's Topics:

   1. Array.prototype.append ? (Jordi Bunster)



-- Forwarded message --
From: Jordi Bunster mailto:jbuns...@microsoft.com>>
To: "es-discuss@mozilla.org "
mailto:es-discuss@mozilla.org>>
Cc:
Bcc:
Date: Wed, 23 May 2018 02:45:25 +
Subject: Array.prototype.append ?
Has anyone ever suggested Array.prototype.append as an
Array.prototype.push which returns the array itself? It would be
reduce-friendly, same as Set.prototype.add and Map.prototype.set.

Someone has to have, right? 😊
___
es-discuss mailing list
es-discuss@mozilla.org 
https://mail.mozilla.org/listinfo/es-discuss



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Ben Fletcher
Does the `[...oldArr, ...elementsToPushArr]` pattern take care of that for
you? I've always assumed it's much less performant than your form would be,
but I (naively) suppose the implementation could be optimized like anything
else

On Wed, May 23, 2018 at 8:01 AM  wrote:

> Send es-discuss mailing list submissions to
> es-discuss@mozilla.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.mozilla.org/listinfo/es-discuss
> or, via email, send a message with subject or body 'help' to
> es-discuss-requ...@mozilla.org
>
> You can reach the person managing the list at
> es-discuss-ow...@mozilla.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of es-discuss digest..."
> Today's Topics:
>
>1. Array.prototype.append ? (Jordi Bunster)
>
>
>
> -- Forwarded message --
> From: Jordi Bunster 
> To: "es-discuss@mozilla.org" 
> Cc:
> Bcc:
> Date: Wed, 23 May 2018 02:45:25 +
> Subject: Array.prototype.append ?
> Has anyone ever suggested Array.prototype.append as an
> Array.prototype.push which returns the array itself? It would be
> reduce-friendly, same as Set.prototype.add and Map.prototype.set.
>
> Someone has to have, right? 😊
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss