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.
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
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(),
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
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`.
`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
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
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
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
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
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,
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
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
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`
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
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
},
{
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
17 matches
Mail list logo