Check out Dart's iterators
Brendan Eich
brendan at mozilla.com
Mon Feb 11 13:19:40 PST 2013
Domenic Denicola wrote:
>> From: Brendan Eich [mailto:brendan at mozilla.com]
>>
>> Domenic Denicola wrote:
>>>> -----Original Message-----
>>>> From: Brendan Eich [mailto:brendan at mozilla.com]
>>>> Sent: Sunday, February 10, 2013 03:20
>>>> Changing from hasMore/getNext to current/moveNext does not eliminate two methods that can get out of sync. You can imagine one is a property, not a method, but the general case is a getter or C#-style Current method.
>>> Ah, the fact that it could be a getter does reduce it to the original two-out-of-sync-methods case, right. Thanks!
>> Rather, current *must* be a getter (or really, a method). The iteration protocol abstracts over all implementations using structural type(s), where the signature(s) must be the same for all iterators. Not all iterators want to expose a writable data property, .current.
>>
>> Or did you mean a non-configurable, non-writable data property named current that is updated by moveNext? That would make all iterators be exotic objects, which is a non-starter.
>
> I don't see why all iterators would have to have the same "kind" of property descriptor? I.e. if one iterator wanted a getter, and others wanted a writable, configurable data property, what's the problem there?
That might be ok, depending on point of view -- ES5 makes the difference
observable. But I agree it would be strange to come to depend on it.
My point was more that a writable configurable data property is an
anti-pattern for defensively coded iterators.
> It seems your structural type(s)/signature(s) comment is heading in this direction, but I don't understand why.
Hope that helps,
/be
More information about the es-discuss
mailing list