feat(lua): use callable table as iterator in vim.iter (#23957)

A table passed to `vim.iter` can be a class instance with a `__call`
implementation for the iterator protocol.
This commit is contained in:
Mathias Fußenegger
2023-06-10 20:33:23 +02:00
committed by GitHub
parent b302da9ad2
commit 302d3cfb96
3 changed files with 36 additions and 0 deletions

View File

@@ -4,6 +4,15 @@ local matches = helpers.matches
local pcall_err = helpers.pcall_err
describe('vim.iter', function()
it('new() on iterable class instance', function()
local rb = vim.ringbuf(3)
rb:push("a")
rb:push("b")
local it = vim.iter(rb)
eq({"a", "b"}, it:totable())
end)
it('filter()', function()
local function odd(v)
return v % 2 ~= 0