Module:TableUtil

-- Swaps the first two dimensions of a nested table. -- `tbl` can be an array or a map. -- Note: The order of traversal is non-deterministic. local function transpose(tbl) local function getIterator(t) assert(type(t) == type({}), "`tbl` must be a nested table") if #t > 0 then return ipairs(t) else return pairs(t) end end local arr_t = {} for i_k, i_v in getIterator(tbl) do		for j_k, j_v in getIterator(i_v) do			arr_t[j_k] = arr_t[j_k] or {} arr_t[j_k][i_k] = j_v end end return arr_t end

return { transpose = transpose, }