-
Notifications
You must be signed in to change notification settings - Fork 34
Drop .toArray from this proposal #142
Comments
Array.from isn’t chainable, and arrays are, by a large margin, the primary thing iterators are converted into. |
See #36 (comment). |
imo (and it is just an opinion), chainability for non-array-like methods should be de-prioritized while the resolution of the pipeline operator proposal is underway
i think this offers a great reason not to add a generic |
Because arrays, like iterators and unlike objects, represent a sequence. Arrays are a natural thing to transform iterators into in a way that objects are not.
It's exactly one additional, very useful method. The champions have repeatedly refused requests to add other variations. I don't think this slope is very slippery. |
I think the presupposition that iterators represent a sequence is biased. Yes, they ultimately take form as a sequence, but only because of their lazy nature. It's easily conceivable that developers are using iterators just as collections (orderless) |
That doesn’t make any sense to me. A collection doesn’t have an order, iterators do. Certainly iterating an unordered collection requires choosing an order, one that may not matter in that use case, but that doesn’t affect the semantics of iterators - which is, explicitly and unavoidably, an ordered sequence of values. |
i get that iterators are structured sequentially, but my point is that the intent with which people use them is not necessarily as a sequence to give an analogous example, arrays are often used to create objects, but they don't have their own |
I just want to throw in that there is the pipeline proposal: https://github.com/tc39/proposal-pipeline-operator/wiki naturals()
.filter(n => n > 20)
.take(20)
|> Array.from(?) It looks kind of wrong but it would make it easy to just chain the result in |
yep i agree. it's why i mentioned |
Arrays are extremely privileged and ubiquitous. For that reason, the |
.toArray
seems needlessly specific since arrays are not the only things that iterators will need to be converted toIt's also redundant because
Array.from
already exists. Would it not be better to leave it up to each class to implement its owniterator -> class instance
constructor (Object.fromEntries
,new Set
/Set.from
, etc.)?The text was updated successfully, but these errors were encountered: