local lib=require("transforms") local adjust=lib.internal.range_adjust local view=lib.internal.table_view function lib.sub(tbl,f,l) checkArg(1,tbl,'table') local r,s={},#tbl f,l=adjust(f,l,s) l=math.min(l,s) for i=math.max(f,1),l do r[#r+1]=tbl[i] end return r end function lib.partition(tbl,partitioner,dropEnds,f,l) checkArg(1,tbl,'table') checkArg(2,partitioner,'function','table') checkArg(3,dropEnds,'boolean','nil') if type(partitioner)=='table'then return lib.partition(tbl,function(e,i,tbl) return lib.first(tbl,partitioner,i) end,dropEnds,f,l) end local s=#tbl f,l=adjust(f,l,s) local cut=view(tbl,f,l) local result={} local need=true local exp=function()if need then result[#result+1]={}need=false end end local i=f while i<=l do local e=cut[i] local ds,de=partitioner(e,i,cut) if ds==true then ds,de=i,i elseif ds==false then ds,de=nil,nil end if ds~=nil then ds,de=adjust(ds,de,l) ds=ds>=i and ds end if not ds then exp() table.insert(result[#result],e) else local sub=lib.sub(cut,i,not dropEnds and de or(ds-1)) if#sub>0 then exp() result[#result+math.min(#result[#result],1)]=sub end local ensured=math.max(math.max(de or ds,ds),i) if de and ds and de