# HG changeset patch # User Matthew Wild # Date 1665077680 -3600 # Node ID e894677359e5b19b772cc65b710bdb2085b8c67b # Parent 19113f232423db83ba25d70ed1bffb7d82a6fc8e util.iterators: join: Work even with only a single iterator in the chain diff -r 19113f232423 -r e894677359e5 spec/util_iterators_spec.lua --- a/spec/util_iterators_spec.lua Thu Oct 06 16:00:39 2022 +0100 +++ b/spec/util_iterators_spec.lua Thu Oct 06 18:34:40 2022 +0100 @@ -10,6 +10,14 @@ 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 () diff -r 19113f232423 -r e894677359e5 util/iterators.lua --- a/util/iterators.lua Thu Oct 06 16:00:39 2022 +0100 +++ b/util/iterators.lua Thu Oct 06 18:34:40 2022 +0100 @@ -240,7 +240,8 @@ 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;