util.iterators: join: Work even with only a single iterator in the chain

This commit is contained in:
Matthew Wild 2022-10-06 18:34:40 +01:00
parent 12fc0febf1
commit 08b49654d9
2 changed files with 10 additions and 1 deletions

View file

@ -10,6 +10,14 @@ describe("util.iterators", function ()
end
assert.same(output, expect);
end);
it("should work with only a single iterator", function ()
local expect = { "a", "b", "c" };
local output = {};
for x in iter.join(iter.values({"a", "b", "c"})) do
table.insert(output, x);
end
assert.same(output, expect);
end);
end);
describe("sorted_pairs", function ()

View file

@ -240,7 +240,8 @@ function join_methods:prepend(f, s, var)
end
function it.join(f, s, var)
return setmetatable({ {f, s, var} }, join_mt);
local t = setmetatable({ {f, s, var} }, join_mt);
return t, { t, 1 };
end
return it;