KoboldAI-Client/extern/lualibs/pl/List.lua

7 lines
5.8 KiB
Lua

-- Penlight 1.11.0-1 | /lua/pl/List.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,b,c,d=table.insert,table.remove,table.concat,table.sort;local setmetatable,getmetatable,type,tostring,string=setmetatable,getmetatable,type,tostring,string;local e=require'pl.tablex'local f,g,h,i,j,k=e.filter,e.imap,e.imap2,e.reduce,e.transform,e.removevalues;local l=e.sub;local m=require'pl.utils'local n=require'pl.class'local o,p,q,r=m.array_tostring,m.split,m.assert_arg,m.function_arg;local s=e._normalize_slice;local t=m.stdmt.MultiMap;local u=m.stdmt.List;local v;n(nil,nil,u)local function w(x,y)local z=u;if y then z=getmetatable(y)end;return setmetatable(x,z)end;local function A(x)return type(x)=='table'and not getmetatable(x)and#x>0 end;function u._create(B)if A(B)then return B end end;function u:_init(B)if self==B then return end;if B then for C in v(B)do a(self,C)end end end;u.new=u;function u:clone()local D=w({},self)D:extend(self)return D end;function u:append(E)a(self,E)return self end;u.push=a;function u:extend(F)q(1,F,'table')for E=1,#F do a(self,F[E])end;return self end;function u:insert(E,G)q(1,E,'number')a(self,E,G)return self end;function u:put(G)return self:insert(1,G)end;function u:remove(E)q(1,E,'number')b(self,E)return self end;function u:remove_value(G)for E=1,#self do if self[E]==G then b(self,E)return self end end;return self end;function u:pop(E)if not E then E=#self end;q(1,E,'number')return b(self,E)end;u.get=u.pop;local H=e.find;u.index=H;function u:contains(G)return H(self,G)and true or false end;function u:count(G)local I=0;for E=1,#self do if self[E]==G then I=I+1 end end;return I end;function u:sort(J)if J then J=r(1,J)end;d(self,J)return self end;function u:sorted(J)return u(self):sort(J)end;function u:reverse()local x=self;local K=#x;for E=1,K/2 do x[E],x[K]=x[K],x[E]K=K-1 end;return self end;function u:minmax()local L,M=1e70,-1e70;for E=1,#self do local C=self[E]if C<L then L=C end;if C>M then M=C end end;return L,M end;function u:slice(N,O)return l(self,N,O)end;function u:clear()for E=1,#self do b(self)end;return self end;local P=1.0e-10;function u.range(Q,R,S)if not R then R=Q;Q=1 end;if S then q(3,S,'number')if math.ceil(S)~=S then R=R+P end else S=1 end;q(1,Q,'number')q(2,R,'number')local x=u()for E=Q,R,S do a(x,E)end;return x end;function u:len()return#self end;function u:chop(T,U)return k(self,T,U)end;function u:splice(V,W)q(1,V,'number')V=V-1;local E=1;for C in v(W)do a(self,E+V,C)E=E+1 end;return self end;function u:slice_assign(T,U,X)q(1,T,'number')q(1,U,'number')T,U=s(self,T,U)if U>=T then self:chop(T,U)end;self:splice(T,X)return self end;function u:__concat(F)q(1,F,'table')local D=self:clone()D:extend(F)return D end;function u:__eq(F)if#self~=#F then return false end;for E=1,#self do if self[E]~=F[E]then return false end end;return true end;function u:join(Y)Y=Y or''q(1,Y,'string')return c(o(self),Y)end;u.concat=c;local function Z(_)local a0=tostring(_)if type(_)=='string'then a0='"'..a0 ..'"'end;return a0 end;function u:__tostring()return'{'..self:join(',',Z)..'}'end;function u:foreach(a1,...)a1=r(1,a1)for E=1,#self do a1(self[E],...)end end;local function a2(y,a3)local a4=y[a3]if not a4 then error(type(y).." does not have method "..a3,3)end;return a4 end;function u:foreachm(a3,...)for E=1,#self do local y=self[E]local a4=a2(y,a3)a4(y,...)end end;function u:filter(a1,a5)return w(f(self,a1,a5),self)end;function u.split(a0,Y)q(1,a0,'string')return w(p(a0,Y))end;function u:map(a1,...)return w(g(a1,self,...),self)end;function u:transform(a1,...)j(a1,self,...)return self end;function u:map2(a1,D,...)return w(h(a1,self,D,...),self)end;function u:mapm(a3,...)local a6={}for E=1,#self do local _=self[E]local a7=a2(_,a3)a6[E]=a7(_,...)end;return w(a6,self)end;local function a8(a9,a4)return function(self,...)return self[a9](self,a4,...)end end;function u.default_map_with(aa)return function(self,a3)local ab;if aa then local a4=a2(aa,a3)ab=a8('map',a4)else ab=a8('mapn',a3)end;getmetatable(self)[a3]=ab;return ab end end;u.default_map=u.default_map_with;function u:reduce(a1)return i(a1,self)end;function u:partition(a1,...)a1=r(1,a1)local a6={}for E=1,#self do local _=self[E]local z=a1(_,...)if z==nil then z='<nil>'end;if not a6[z]then a6[z]=u()end;a6[z]:append(_)end;return setmetatable(a6,t)end;function u:iter()return v(self)end;function u.iterate(X)if type(X)=='string'then local V=0;local K=#X;local ac=string.sub;return function()V=V+1;if V>K then return nil else return ac(X,V,V)end end elseif type(X)=='table'then local V=0;local K=#X;return function()V=V+1;if V>K then return nil else return X[V]end end elseif type(X)=='function'then return X elseif type(X)=='userdata'and io.type(X)=='file'then return X:lines()end end;v=u.iterate;return u