mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 12:45:17 -07:00
fix(vim.iter): use correct cmp function when truncating tail in take
(#27998)
This commit is contained in:
parent
3d9c028a4c
commit
ca6dbf3558
@ -709,7 +709,8 @@ end
|
||||
---@private
|
||||
function ListIter:take(n)
|
||||
local inc = self._head < self._tail and 1 or -1
|
||||
self._tail = math.min(self._tail, self._head + n * inc)
|
||||
local cmp = self._head < self._tail and math.min or math.max
|
||||
self._tail = cmp(self._tail, self._head + n * inc)
|
||||
return self
|
||||
end
|
||||
|
||||
|
@ -247,6 +247,12 @@ describe('vim.iter', function()
|
||||
eq({ 4, 3, 2, 1 }, vim.iter(t):take(5):totable())
|
||||
end
|
||||
|
||||
do
|
||||
local t = { 4, 3, 2, 1 }
|
||||
eq({ 1, 2, 3 }, vim.iter(t):rev():take(3):totable())
|
||||
eq({ 2, 3, 4 }, vim.iter(t):take(3):rev():totable())
|
||||
end
|
||||
|
||||
do
|
||||
local t = { 4, 3, 2, 1 }
|
||||
local it = vim.iter(t)
|
||||
|
Loading…
Reference in New Issue
Block a user