aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/iter.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-09-01 13:01:24 -0700
committerGitHub <noreply@github.com>2024-09-01 13:01:24 -0700
commit61e9137394fc5229e582a64316c2ffef55d8d7af (patch)
treec0f380b5efa26bed8c13d2d7b192c0c89568222a /runtime/lua/vim/iter.lua
parent6913c5e1d975a11262d08b3339d50b579e6b6bb8 (diff)
downloadrneovim-61e9137394fc5229e582a64316c2ffef55d8d7af.tar.gz
rneovim-61e9137394fc5229e582a64316c2ffef55d8d7af.tar.bz2
rneovim-61e9137394fc5229e582a64316c2ffef55d8d7af.zip
docs: misc #28970
Diffstat (limited to 'runtime/lua/vim/iter.lua')
-rw-r--r--runtime/lua/vim/iter.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/runtime/lua/vim/iter.lua b/runtime/lua/vim/iter.lua
index 6bddf0bc5e..4bbcaf16db 100644
--- a/runtime/lua/vim/iter.lua
+++ b/runtime/lua/vim/iter.lua
@@ -6,10 +6,12 @@
--- of each pipeline stage is input to the next stage. The first stage depends on the type passed to
--- `vim.iter()`:
---
---- - List tables (arrays, |lua-list|) yield only the value of each element.
---- - Holes (nil values) are allowed.
+--- - Lists or arrays (|lua-list|) yield only the value of each element.
+--- - Holes (nil values) are allowed (but discarded).
+--- - Use pairs() to treat array/list tables as dicts (preserve holes and non-contiguous integer
+--- keys): `vim.iter(pairs(…))`.
--- - Use |Iter:enumerate()| to also pass the index to the next stage.
---- - Or initialize with ipairs(): `vim.iter(ipairs(…))`.
+--- - Or initialize with ipairs(): `vim.iter(ipairs(…))`.
--- - Non-list tables (|lua-dict|) yield both the key and value of each element.
--- - Function |iterator|s yield all values returned by the underlying function.
--- - Tables with a |__call()| metamethod are treated as function iterators.
@@ -1034,7 +1036,7 @@ function Iter.new(src, ...)
if type(k) ~= 'number' or k <= 0 or math.floor(k) ~= k then
return Iter.new(pairs(src))
end
- t[#t + 1] = v
+ t[#t + 1] = v -- Coerce to list-like table.
end
return ArrayIter.new(t)
end