mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +00:00
fixed bug in filter_inplace for single element collections
This commit is contained in:
parent
0691f2bd36
commit
292345b953
@ -99,13 +99,13 @@ end
|
||||
|
||||
--filters a sequence in place, modifying it
|
||||
function functional.filter_inplace(t, f)
|
||||
local write_i = 1
|
||||
local write_i = 0
|
||||
local n = #t --cache, so splitting the sequence doesn't stop iteration
|
||||
for i = 1, n do
|
||||
local v = t[i]
|
||||
if f(v, i) then
|
||||
t[write_i] = v
|
||||
write_i = write_i + 1
|
||||
t[write_i] = v
|
||||
end
|
||||
if i ~= write_i then
|
||||
t[i] = nil
|
||||
|
Loading…
Reference in New Issue
Block a user