mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
committed by
GitHub
parent
b302da9ad2
commit
302d3cfb96
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user