New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop .asIndexedPairs from this proposal or replace it with .entries #143
Comments
|
I'm here to support renaming asIndexedPairs to |
If So if there is a good reason to not include the index in all methods; I will also vote for renaming |
not sure if what @ljharb said about keeping a hypothetical wrt performance, I believe including the index only costs constant space (and linear runtime if you count variable assignment). negligible if you ask me |
|
I vote for keeping Also of course anyone can just |
fwiw I picked the name |
I will check if there are issues with this, if not I will fold it in. thanks for the suggestion. |
To throw in another option to bikeshed about: in npm itertools, ballvalve, Python, Rust std Iterator, and Rust itertools, this method is named |
I don't understand what "interoperability" refers to in
None of the standard iterators that implement the iterator protocol have an If |
i would personally prefer |
|
|
And that's exactly the issue I have, the reason why I think the name does not apply here. I'd want something that emphasises adding indices to the values in the iterator. Key-value tuples are fine for the entries of collections, but I don't think of an iterator as containing entries. |
|
@bergus However, #143 (comment) is compelling. |
Clojure uses |
Confusing let users = new Map()
users.set('alice', new User())
users.set('bob', new User())
users.entries().entries() Here, entries means something entirely different on each invocation, but with deceptively similar return types. With some indirection, one could easily get the wrong result without necessarily crashing and revealing the mistake. function saveUsersToLocalStorage(users) {
const data = {}
for (const [name, user] of users.entries()) {
data[name] = user.serializable()
}
localStorage.users = JSON.stringify(data)
}
let users = new Map()
users.set('alice', new User())
users.set('bob', new User())
saveUsersToLocalStorage(users.entries()) Unless you're using some sort of static type checking, this could be very hard to track down. |
I don't like I also worry about potential confusion with So I vote for |
Assuming the iterator
.map
has about the same function signature as the array.map
:.asIndexedPairs
seems like an overengineering wheniterator.map((value, index) => [value, index])
would effortlessly achieve the same result, not to mention be more versatileif we must keep
.asIndexedPairs
, can it be renamed as.entries
for interoperability with virtually everything that implements the iterator protocol?The text was updated successfully, but these errors were encountered: