-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Split out ArrayIter
from vim.iter()
#28941
Comments
Note: review #24746 before commenting hereHaving a way to tell
Yeah, I also advocated for having the same signature for the callbacks, regardless of list vs dict. There were valid arguments for the current behavior, but I still prefer the predictable and consistent signature. |
This comment was marked as outdated.
This comment was marked as outdated.
ArrayIter
from vim.iter
ArrayIter
from vim.iter()
Not in favor of that. It would be annoying if the builtin
To make progress, let's be very precise and concrete. Currently, we've identified that an opt-in is needed. Let's focus on that rather than more general statements about an "all knowing interface". |
If so, then yes it's not a good idea. However, I don't think it would ever be needed. From what I can tell it's basically a drop in replacement with additional functionality ( I think we also need specialized versions so
And overall we do not make any assumptions about how a table is expected to be iterated. Just like with
Ok, let's start with the removal/deprecation of the sniffing logic. |
Starting with an opt-in is much lower risk and more tractable. |
Problem
Do we still think it was the right choice to make
vim.iter
handle arrays and general tables together? Could we consider splitting this (as Lua does withpairs
andipairs
), so the right behaviour can be opted in appropriately so it is less confusing?E.g. I was experimenting with
vim.iter
today and wanted to port:which with
vim.iter
is:However, it really wasn't obvious to me that the map function only takes a single argument, unlike
ipairs
which gives you both the index and the value.I know
vim.iter(pairs(t))
is a thing, but it's just an unnecessary footgun andvim.iter()
behaving very differently depending on the shape of the keys seems problematic to me. The user may have a table that just happens to be indexed my integers but should be treated as a regular table, e.g. for atable<id: integer, object: table>
type.Expected behavior
I propose that
vim.iter(t) == vim.iter(pairs(t))
and we add something likevim.arrayiter(t)
so the specialized behaviour can be opted in. This would also allow us to:vim.iter()
thereby making all methods ofvim.iter(...)
have the same signature.Overall I think removing some of this extra smartness will simplify the mental model of
vim.iter
which for me is currently a bit overloaded.The text was updated successfully, but these errors were encountered: