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

Jordan Harband ljharb at gmail.com
Wed Aug 9 07:41:14 UTC 2017


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 <naveen.chwl at gmail.com>
wrote:

> `iterable`, excuse me
>
> On Wed, 9 Aug 2017 at 13:05 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>
>> It would be in the `iteratable` `protocol` (interface)
>>
>> On Wed, 9 Aug 2017 at 13:03 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>
>>> You're thinking of `iterator`
>>>
>>> On Wed, 9 Aug 2017 at 13:01 Jordan Harband <ljharb at gmail.com> 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, Naveen Chawla <naveen.chwl at gmail.com>
>>>> wrote:
>>>>
>>>>> 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 there existed no more direct way of transforming from iterable to
>>>>> object. All entries arrays are iterable, but not all iterables are entries
>>>>> arrays, which means that iterable is the more generic concept than entries,
>>>>> meaning that iterable, not entries, is the more suitable starting point for
>>>>> this functionality.
>>>>>
>>>>> `Object.fromIterable(iterable, keyFromElement[, valueFromElement])` is
>>>>> more verbose than `iterable.toObject(keyFromElement[,
>>>>> valueFromElement]) and doesn't allow chaining after iterable transformation
>>>>> methods (like `filter` etc.)
>>>>>
>>>>> On Tue, 8 Aug 2017 at 16:23 Naveen Chawla <naveen.chwl at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> OK thanks for the link - can you explain where the complexity is in
>>>>>> my proposal?
>>>>>>
>>>>>> On Tue, 8 Aug 2017 at 16:14 T.J. Crowder <
>>>>>> tj.crowder at farsightsoftware.com> wrote:
>>>>>>
>>>>>>> On Tue, Aug 8, 2017 at 11:39 AM, Naveen Chawla <
>>>>>>> naveen.chwl at gmail.com> wrote:
>>>>>>> > Furthermore, if you use entries, this allows `[key, value]` entries
>>>>>>> > with object keys to be transformed into objects (which is not
>>>>>>> > allowed by `Object.fromEntries`):
>>>>>>>
>>>>>>> With respect, please do have a *thorough* read of my first reply in
>>>>>>> this thread, the ensuing discussion with Darien, and Darien's proposal, in
>>>>>>> particular [this bit of it](https://github.com/bathos/
>>>>>>> object-from-entries#additional-arguments). Those various sources
>>>>>>> explain my comment about complexity and how `Object.fromEntries` might do
>>>>>>> what you want.
>>>>>>>
>>>>>>> -- T.J. Crowder
>>>>>>>
>>>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170809/3eb6af4c/attachment.html>


More information about the es-discuss mailing list