Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Copyright (c) 2016 Paul Kosel
- --
- -- MIT License
- --
- -- 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 function e(s)
- local h=setmetatable({},{__index=_ENV or getfenv()})if setfenv then setfenv(s,h)end;return s(h)or h end
- local t=e(function(s,...)local h={}function h.identity(r)return r end
- function h.isEqual(r,d)if(type(r)~=type(d))then
- return false end
- if(type(r)=="table")then for l,r in pairs(r)do
- if(d[l]~=r)then return false end end;return true end;return r==d end;function h.toBoolean(r)return r and true or false end
- function h.isCallable(r)if(
- type(r)=="table")then return
- type(getmetatable(r).__call)=="function"end;return
- type(r)=="function"end;function h.isTable(r)return type(r)=="table"end
- function h.isNil(r)return r==nil end
- function h.isArray(r)if not h.isTable(r)then return false end;local d=0;for l,l in pairs(r)do d=d+1;if
- h.isNil(r[d])then return false end end;return true end
- function h.isIterable(r)return h.toBoolean(pcall(pairs,r))end;function h.isString(r)return type(r)=="string"end
- function h.isEmpty(r)if h.isNil(r)then return
- true end;if h.isString(r)then return#r==0 end;if h.isTable(r)then return
- next(r)==nil end;return true end;function h.isNumber(r)return type(r)=="number"end;function h.isNaN(r)return
- h.isNumber(r)and r~=r end;function h.isFinite(r)if
- not h.isNumber(r)then return false end
- return r>-math.huge and r<math.huge end;function h.isBoolean(r)return
- type(r)=="boolean"end
- function h.isInteger(r)return type(r)=="number"and
- math.floor(r)==r end
- function h.once(r)local d=false;local l=false;return
- function(...)if(d)then return l end;l=r(unpack({...}))return l end end
- function h.functions(r)local d={}for l,u in pairs(r)do if(type(u)=="function")then
- table.insert(d,l)end end;return d end
- function h.clone(r)if(type(r)~="table")then return r end;local d={}for l,u in pairs(r)do
- d[h.clone(l)]=h.clone(u)end;return d end
- function h.result(r,d,...)
- if(r[d])then
- if(h.isCallable(r[d]))then return r[d](r,...)else return r[d]end elseif _.isCallable(d)then return d(r,...)end end
- function h.memoize(r,d)local l=d or h.identity;local u={}
- return function(...)for m,f in pairs(u)do if(h.isEqual(m,{...}))then
- return f end end;local c=r(...)
- u[{...}]=c;return c end end;function h.after(r,d)local u,c=0,d
- return function(...)u=u+1;if(u>=c)then return r(...)end end end
- function h.compose(...)local r={...}return
- function(...)
- local d=r[1](...)for l,u in pairs(r)do if(l~=1)then d=u(d)end end;return d end end;function h.pipe(r,...)return h.compose(...)(r)end;function h.times(r,d,...)local l={}for u=1,r do
- l[u]=d(u,...)end;return l end;function h.bind(r,d)return
- function(...)return r(d,...)end end
- function h.bindn(r,...)local d={...}return function(...)return
- r(unpack(d),...)end end;function h.tap(r,d,...)d(r,...)return r end;return h end)
- local a=e(function(s,...)local h={}
- function h.each(r,d,...)for l,u in pairs(r)do d(l,u,...)end end
- function h.at(r,...)local d={...}local l={}for u,c in pairs(d)do l[#l+1]=r[c]end;return l end
- function h.count(r,d)if(d==nil)then return#r end;local l=0;for u,c in pairs(r)do
- if(_.isEqual(d,d))then l=l+1 end end;return l end
- function h.cycle(r,d)d=d or 1;if d<=0 then return function()end end;local l,u;local c=0
- while true do
- return function()l=
- l and next(r,l)or next(r)u=not u and l or u;if d then c=
- (l==u)and c+1 or c;if c>d then return end end
- return l,r[l]end end end
- function h.map(r,d)local l={}for u,c in pairs(r)do l[u]=d(u,c)end;return l end
- function h.reduce(r,d)local l=""for u,c in pairs(r)do l=d(l,c)end;return l end
- function h.mapReduce(r,d)local l={}local u=""for c,m in pairs(r)do u=d(u,m)l[#l+1]=u end;return l end
- function h.detect(r,d)for l,u in pairs(r)do
- if(_.isCallable(d))then
- if(_.isEqual(u,d(u)))then return l end else if(_.isEqual(d,u))then return l end end end;return nil end;function h.all(r,d)
- for l,u in pairs(r)do if(not d(l,u))then return false end end;return true end;function h.include(r,d)return
- h.detect(r,d)~=nil end;return h end)
- local o=e(function(s,...)local h={}function h.toArray(...)return{...}end;function h.find(r,d,l)for u=(l or 1),#r do
- if(r[u]==d)then return u end end end
- function h.reverse(r)
- local d={}for l=#r,1,-1 do d[#r-l+1]=r[l]end;return d end
- function h.selectWhile(r,d,...)local l={}for u=1,#r do
- if(d(u,r[u],...))then l[#l+1]=r[u]else break end end;return l end
- function h.dropWhile(r,d,...)local l={}for u=1,#r do
- if(not d(u,r[u],...))then select[#l+1]=r[u]else break end end;return l end
- function h.indexOf(r,d)for l,u in pairs(r)do if(d==u)then return l end end end
- function h.lastIndexOf(r,d)local l;for u,c in pairs(r)do if(d==c)then l=u end end;return l end
- function h.push(r,...)for d,l in pairs({...})do r[#r+1]=l end;return r end;function h.pop(r)local d=r[1]table.remove(r,1)return d end
- function h.unshift(r)local d=r[
- #r]table.remove(r,#r)return d end
- function h.pull(r,...)local d={}for u,c in pairs({...})do d[c]=true end;local l={}for u,c in pairs(r)do if
- (not d[c])then l[#l+1]=c end end;return l end
- function h.removeRange(r,d,l)for u=d,l do table.remove(r,d)end;return r end
- function h.slice(r,d,l)local u={}for c=d,l do u[#u+1]=r[c]end;return u end
- function h.first(r,d)local l={}for u=1,(d or 1)do l[u]=r[u]end;return l end
- function h.initial(r,d)local l={}for u=1,#r- (d or 1)do l[u]=r[u]end;return l end
- function h.last(r,d)local l={}for u=#r- (d or 1),#r do l[#l+1]=r[u]end;return l end;function h.nth(r,d)return r[d]end
- function h.difference(r,d)local u={}local c={}
- for l,m in pairs(d)do c[m]=true end;for l,m in pairs(r)do if(not c[m])then u[#u+1]=m end end;return
- u end
- function h.union(...)local r={}local d={}
- for l,u in pairs({...})do for l,c in pairs(u)do
- if(not d[c])then r[#r+1]=c;d[c]=true end end end;return end
- function h.unique(r)local d={}local l={}for u,c in pairs(r)do
- if(not d[c])then l[#l+1]=c;d[c]=true end end;return l end
- function h.isunique(r)local d={}local l={}for u,c in pairs(r)do
- if(not d[c])then d[c]=true else return false end end;return true end
- function h.append(r,d)local l=r;for u,c in pairs(d)do l[#l+d]=c end;return l end
- function h.range(r,d,l)local l=l or 1;local u={}if(not d)then for c=0,r,l do u[#u+1]=c end else
- for c=r,d,l do u[#u+1]=c end end;return u end;function h.rep(r,d)local l={}for u=1,d do l[#l+1]=r end;return l end
- function h.concat(r,d)
- local l=""local d=d or""for u,r in ipairs(r)do l=l..d..r end;return l end
- function h.split(r,d)local d=d or" "local l={}for u in r:gmatch("[^"..d.."]+")do
- table.insert(l,u)end;return l end;return h end)local i={}_G._=setmetatable({},{__index=i})
- local function n(s,h)if(not s)then return end;for r,d in
- pairs(s)do if(not h[r])then h[r]=d end end end;n(t,i)n(o,i)n(a,i)n(Helper,i)i._MODULES={}
- i._MODULES.Core=true;i._MODULES.Array=i.toBoolean(o)
- i._MODULES.Table=i.toBoolean(a)i._MODULES.Computercraft=i.toBoolean(CC)
- i._MODULES.Helper=i.toBoolean(Helper)
- function i.new(s)local h={_value=s,_wrapped=true}
- local function r(d,l)if(l=="value")then
- return function()return h._value end end
- if(i.isCallable(i[l]))then return function(...)return
- i.new(i[l](h._value,...))end end end;return setmetatable(h,{__index=r})end;function i.chain(s)return i.new(s)end
Add Comment
Please, Sign In to add comment