Nicolas B. Pierron (2018-07-19T12:53:53.000Z)
On Wed, Jul 18, 2018 at 6:43 PM, Mike Samuel <mikesamuel at gmail.com> wrote:
> On Wed, Jul 18, 2018 at 2:06 PM Nicolas B. Pierron
> <nicolas.b.pierron at mozilla.com> wrote:
>> Stupid question, but why are some of these methods implemented on
>> String, Array, TypedArray, Map and Set, while all of them are
>> Iteratable?
>
>
> String is different from the others.
> The String index methods deal with a contiguous subsequence of the sequence,
> not the index of an element in the sequence.

I am not sure why this would prevent us from adding an Iteratable
object with common properties.  `Iteratable.prototype.foo` can exist
at the same time as `String.prototype.foo`, and calling the `foo`
property on a String will result in calling `String.prototype.foo`.

Also one could implement a naïve/default implementation of
`reverseOrder` which allocates a temporary array for object which have
no random accesses capabilities.

````
  Iteratable.prototype.reverseOrder = function* () {
      for (let e of [...this].reverse())
           yield e;
  }
```

>>
>> If we were to add all these methods on Iteratable, then one could add
>> a `reverse` generator property on Iteratable.
>
>
> Reverse is problematic on String.  The index of a codepoint can't be
> subtracted from String.length since length is not the count of codepoints.

Don't take me wrong, I was not suggesting to add a `reverse` property.
I was suggesting to add the Iteratable object in the prototype chain
such that someone can implement extra property on the Iteratable /
Iteratable.prototype object.

Among list of nice Iteratable property that one might add, and which
might not be part of the standard are things like:
  chain, take, skip, takeWhile, skipWhile, repeat, zip, enumerate,
range, stepBy, …

Another option would be to just add a property named `iter` which
returns an Iteratable object.

-- 
Nicolas B. Pierron
nicolas.b.pierron at gmail.com (2018-07-19T12:58:05.178Z)
On Wed, Jul 18, 2018 at 6:43 PM, Mike Samuel <mikesamuel at gmail.com> wrote:
> On Wed, Jul 18, 2018 at 2:06 PM Nicolas B. Pierron
> <nicolas.b.pierron at mozilla.com> wrote:
>> Stupid question, but why are some of these methods implemented on
>> String, Array, TypedArray, Map and Set, while all of them are
>> Iteratable?
>
>
> String is different from the others.
> The String index methods deal with a contiguous subsequence of the sequence,
> not the index of an element in the sequence.

I am not sure why this would prevent us from adding an Iteratable
object with common properties.  `Iteratable.prototype.foo` can exist
at the same time as `String.prototype.foo`, and calling the `foo`
property on a String will result in calling `String.prototype.foo`.

Also one could implement a naïve/default implementation of
`reverseOrder` which allocates a temporary array for object which have
no random accesses capabilities.

```
  Iteratable.prototype.reverseOrder = function* () {
      for (let e of [...this].reverse())
           yield e;
  }
```

>>
>> If we were to add all these methods on Iteratable, then one could add
>> a `reverse` generator property on Iteratable.
>
>
> Reverse is problematic on String.  The index of a codepoint can't be
> subtracted from String.length since length is not the count of codepoints.

Don't take me wrong, I was not suggesting to add a `reverse` property.
I was suggesting to add the Iteratable object in the prototype chain
such that someone can implement extra property on the Iteratable /
Iteratable.prototype object.

Among list of nice Iteratable property that one might add, and which
might not be part of the standard are things like:
  chain, take, skip, takeWhile, skipWhile, repeat, zip, enumerate,
range, stepBy, …

Another option would be to just add a property named `iter` which
returns an Iteratable object.