You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
It could look like a new proposal, but since this proposal includes Iterator.prototype.toArray method, seems, it should be opened here and, maybe, be a part of this proposal.
So, this proposal contains .toArray, by why it's limited only to arrays? Instead of adding methods for each collections type (.toObject, .toSet, etc.), we could add one: .to(Collection) and a protocol for that.
Adding .toArray to this proposal is adding the same, but only for arrays, more other, we have an additional simple way of conversion to arrays - spread operator.
So, how should work .to method? It's just passing this to the method of the passed constructor, the name of this method is a part of this protocol. So, what could be used as this protocol?
It could be .fromIterable method or @@fromIterable well-known symbol.
More other, since here used iterables protocol, it could be added not only to Iterator.prototype but also to prototypes of all iterables, but it's not a part of this proposal...
Symbol.fromIterable=Symbol('Symbol.fromIterable');Iterator.prototype.to=functionto(Constructor){returnConstructor[Symbol.fromIterable](this);};Array[Symbol.fromIterable]=Observable[Symbol.fromIterable]=function(iterable){returnthis.from(iterable);};Object[Symbol.fromIterable]=function(iterable){returnthis.fromEntries(iterable);};Map[Symbol.fromIterable]=Set[Symbol.fromIterable]=WeakMap[Symbol.fromIterable]=WeakSet[Symbol.fromIterable]=Iterator[Symbol.fromIterable]=Object.getPrototypeOf(Int8Array)[Symbol.fromIterable]=URLSearchParams[Symbol.fromIterable]=function(iterable){returnnewthis(iterable);};// as an optionArray.prototype.to=Map.prototype.to=Set.prototype.to=Object.getPrototypeOf(Int8Array).prototype.to=URLSearchParams.prototype.to=Iterator.prototype.to;
The text was updated successfully, but these errors were encountered:
Yes, a generic collect method was considered in the Iterator Helpers proposal but left out due to complexity. I believe the author of that proposal intends to bring a separate proposal up after Iterator Helpers is complete (hopefully) that covers this generic collect. So I'm going to forego including it here. Generally, I agree that using Object.fromEntries is reasonable; and indeed, the pipeline operator would help readability there too.
I explained this conception here. Copy-paste:
It could look like a new proposal, but since this proposal includes
Iterator.prototype.toArray
method, seems, it should be opened here and, maybe, be a part of this proposal.So, this proposal contains
.toArray
, by why it's limited only to arrays? Instead of adding methods for each collections type (.toObject
,.toSet
, etc.), we could add one:.to(Collection)
and a protocol for that.Instead of
we could use a pipeline operator:
But it's mixin of different operators and readable not very good.
In my opinion, the chaining of methods could be better:
Adding
.toArray
to this proposal is adding the same, but only for arrays, more other, we have an additional simple way of conversion to arrays - spread operator.So, how should work
.to
method? It's just passingthis
to the method of the passed constructor, the name of this method is a part of this protocol. So, what could be used as this protocol?.from
method.At this moment, it's available of
Array
,%TypedArray%
, onObservable
proposal, available proposal for adding.from
method toSet
,Map
,WeakSet
,WeakMap
.But it missed at least on
Object
(here used.fromEntries
) andURLSearchParams
..fromIterable
method or@@fromIterable
well-known symbol.More other, since here used iterables protocol, it could be added not only to
Iterator.prototype
but also to prototypes of all iterables, but it's not a part of this proposal...So, something like that:
The text was updated successfully, but these errors were encountered: