Skip to content

Commit

Permalink
updated zip docs
Browse files Browse the repository at this point in the history
  • Loading branch information
italomaia committed May 11, 2019
1 parent 2811296 commit 62abe13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions spec/lua_fun_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ describe('zip output is as expected', function ()
it('iterates over multiple tables at once', function ()
local tmp = {}

for a, b in zip({'a', 'b', 'c'}, {2, 4, 6}) do
table.insert(tmp, {a, b})
for x, y in zip({'a', 'b', 'c'}, {2, 4, 6}) do
table.insert(tmp, {x, y})
end

assert.are.same(tmp, {
Expand Down
13 changes: 6 additions & 7 deletions src/lua_fun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,12 @@ end
-- or keys in `t1` are not found in `tx`, the value of `t1` for such cases will be
-- an array with less than `#{...} + 1` elements.
--
-- @param table
-- @param ... variable number of tables
-- @return table where each key is a key of `t` and each value is
-- a array where the first element is a value of `t` and
-- and the others are values of elements of {...} for each
-- key of `t`.
-- @usage zip({'a', 'b'}, {'x', 'y'}, {5, 6}) # {{'a', 'x', 5}, {'b', 'y', 6}}
-- @param ... variable number of arrays
-- @return table with values of each table grouped by index
-- @usage
-- for x, y, z in zip({'a', 'b'}, {'x', 'y'}, {5, 6}) do
-- print(x, y, z) -- a x 5 then b y 6
-- end
local function zip (...)
local tmp = totable(map(values, {...}))

Expand Down

0 comments on commit 62abe13

Please sign in to comment.