-- Penlight 1.11.0-1 | /lua/pl/permute.lua | https://github.com/lunarmodules/Penlight | License: MIT | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
-- Copyright (C) 2009-2016 Steve Donovan, David Manura.
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local a=require'pl.tablex'local b=require'pl.utils'local c=a.deepcopy;local d=table.insert;local e=b.assert_arg;local f={}function f.order_iter(g)e(1,g,'table')local h=#g;local i={1}local function j()local k=#i;local l=h-k+1;local m=i[k]if m>h then return end;if l==0 then table.remove(i)k=k-1;i[k]=i[k]+1;return g elseif m<=l then g[l],g[m]=g[m],g[l]table.insert(i,1)else table.remove(i)k=k-1;l=l+1;m=i[k]g[l],g[m]=g[m],g[l]i[k]=i[k]+1 end;return j()end;return j end;function f.order_table(g)e(1,g,'table')local n={}for h in f.iter(g)do d(n,c(h))end;return n end;function f.list_iter(...)local o={...}local p={}local q={}local r=#o;for m,s in ipairs(o)do e(m,s,'table')p[m]=1;q[m]=s.n or#s end;local t=0;return function()if p[r]>q[r]then return end;t=t+1;local u={n=#o}local v=true;for m=1,r do u[m]=o[m][p[m]]if v then p[m]=p[m]+1;if p[m]<=q[m]then v=false else if m~=r then p[m]=1 end end end end;return t,b.unpack(u)end end;function f.list_table(...)local j=f.list_iter(...)local w={}local m=1;while true do local x=b.pack(j())if x[1]==nil then return w end;for m=1,x.n do x[m]=x[m+1]end;x.n=x.n-1;w[m]=x;m=m+1 end end;function f.iter(...)b.raise_deprecation{source="Penlight "..b._VERSION,message="function 'iter' was renamed to 'order_iter'",version_removed="2.0.0",deprecated_after="1.9.2"}return f.order_iter(...)end;function f.table(...)b.raise_deprecation{source="Penlight "..b._VERSION,message="function 'table' was renamed to 'order_table'",version_removed="2.0.0",deprecated_after="1.9.2"}return f.order_table(...)end;return f
