Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
It would be in the `iteratable` `protocol` (interface) On Wed, 9 Aug 2017 at 13:03 Naveen Chawla wrote: > You're thinking of `iterator` > > On Wed, 9 Aug 2017 at 13:01 Jordan Harband wrote: > >> An iterator is just an object with a `next` method.

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Jordan Harband
Something is iterable if it has `Symbol.iterator`. Are you saying that every iterable would then need to add a `toObject` method? What happens if it doesn't add it? What value is it if most iterables don't have `toObject` but only some do? On Wed, Aug 9, 2017 at 12:40 AM, Naveen Chawla

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
Java has a great example of such a construct: default interface methods On Wed, 9 Aug 2017 at 13:21 Naveen Chawla wrote: > The `toObject` behaviour doesn't need to be "implemented" on a > per-iterable class basis. It has a constant behaviour: iterate and on each > next(),

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread T.J. Crowder
On Wed, Aug 9, 2017 at 9:24 AM, Jordan Harband wrote: > > I think you're misunderstanding; the function would of course take > an iterable. However, an iterable of what? > > If it's an iterable of objects, then what's the key and what's the > value? What if it's an iterable of

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Jordan Harband
An iterator is just an object with a `next` method. There's no consistent place to put any prototype methods on all iterables, so that's a nonstarter imo. On Wed, Aug 9, 2017 at 12:26 AM, Naveen Chawla wrote: > I do not use entries so I would not use `Object.fromEntries`.

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
`iterable`, excuse me On Wed, 9 Aug 2017 at 13:05 Naveen Chawla wrote: > It would be in the `iteratable` `protocol` (interface) > > On Wed, 9 Aug 2017 at 13:03 Naveen Chawla wrote: > >> You're thinking of `iterator` >> >> On Wed, 9 Aug 2017 at

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Jordan Harband
JS doesn't have interfaces (yet, tho there's a proposal) and regardless, the "interface" for "iterable" is "it has Symbol.iterator, nothing more". The only place a method like this - that produces an object - could possibly exist, is a static method on Object. I've already outlined two existing

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
It is more generic than `fromEntries` On Wed, 9 Aug 2017 at 13:32 Naveen Chawla wrote: > Iterable to object via `Object.fromIterable` > > On Wed, 9 Aug 2017 at 13:31 Jordan Harband wrote: > >> JS doesn't have interfaces (yet, tho there's a proposal) and

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Jordan Harband
I think you're misunderstanding; the function would of course take an iterable. However, an iterable of what? If it's an iterable of objects, then what's the key and what's the value? What if it's an iterable of strings? The only thing that makes sense is if it's an iterable that provides both a

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
I do not use entries so I would not use `Object.fromEntries`. For arrays I could just use reduce, instead of transforming to [key, value] entries, before factoring it into an `arrayToObject` function in my code (which I already do) when I want to do it from more than one place in my code - if

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
You're thinking of `iterator` On Wed, 9 Aug 2017 at 13:01 Jordan Harband wrote: > An iterator is just an object with a `next` method. There's no consistent > place to put any prototype methods on all iterables, so that's a nonstarter > imo. > > On Wed, Aug 9, 2017 at 12:26 AM,

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
The `toObject` behaviour doesn't need to be "implemented" on a per-iterable class basis. It has a constant behaviour: iterate and on each next(), pass the value to the `toKeyFromElement` and `toValueFromElement` callbacks to generate and return an object. There must be some construct by which that

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread T.J. Crowder
On Wed, Aug 9, 2017 at 8:35 AM, Naveen Chawla wrote: > > It would be in the `iteratable` `protocol` (interface) As Jordan said, that's likely to be a nonstarter. The Iterable protocol is *very* lean (exactly one required property) for a reason: So it can be supported with

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
But I accept that this a very tall order for ES On Wed, 9 Aug 2017 at 13:22 Naveen Chawla wrote: > Java has a great example of such a construct: default interface methods > > On Wed, 9 Aug 2017 at 13:21 Naveen Chawla wrote: > >> The `toObject`

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
Iterable to object via `Object.fromIterable` On Wed, 9 Aug 2017 at 13:31 Jordan Harband wrote: > JS doesn't have interfaces (yet, tho there's a proposal) and regardless, > the "interface" for "iterable" is "it has Symbol.iterator, nothing more". > > The only place a method

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Naveen Chawla
Hi Jordan, great question. An iterable of anything! This is the signature: ``` Object.fromIterable(iterable, keyFromElement[, valueFromElement]) ``` Examples follow: Supposing you had an array: ``` [ { countryName: 'UK', population: 6564 }, {

Re: Re: Array.prototype.toObjectByProperty( element=>element.property )

2017-08-09 Thread Jordan Harband
Naveen: `Object.fromIterable(recentCountryNames, countryName=>countryName, countryName=>countriesByName[countryName])` could also be: `Object.fromEntries(Array.from(recentCountryNames, countryName => ([countryName, countriesByName[countryName]])))`, without needing a potentially confusing