function tableCombine(t1, t2) for i=1,#t2 do t1[#t1 + 1] = t2[i] end return t1 end function tableContains(t, predicate) local isFound = false local foundItem = nil for _, v in pairs(t) do if predicate(v) then isFound = true foundItem = v break end end return isFound, foundItem end function tableFilter(t, predicate) local out = {} for i, v in ipairs(t) do if predicate(v, i) then table.insert(out, v) end end return out end function tableCount(t, predicate) local counter = 0 for _, v in ipairs(t) do if predicate(v) then counter = counter + 1 end end return counter end function tableTransform(t, transfromFunction) local out = {} for _, v in ipairs(t) do table.insert(out, transfromFunction(v)) end return out end function tableAccumulate(t, fn, init) local acc = init for k, v in ipairs(t) do if 1 == k and not init then acc = v else acc = fn(acc, v) end end return acc end function tableFirst(t, predicate) for i, v in ipairs(t) do if predicate(v, i) then return v, i end end return nil, 0 end function tableMin(t, isLessFunc) local minIdx = 1 for i, v in ipairs(t) do if not isLessFunc(t[minIdx], v) then minIdx = i end end return t[minIdx], minIdx end function tableMax(t, isGreaterFunc) local maxIdx = 1 for i, v in ipairs(t) do if not isGreaterFunc(t[maxIdx], v) then maxIdx = i end end return t[maxIdx], maxIdx end function tableSlice(tbl, first, last) local sliced = {} for i=first, last or #tbl do sliced[#sliced+1] = tbl[i] end return sliced end function tableMove(t, elementOrIndex, newPosition) local index if type(elementOrIndex) == "number" then index = elementOrIndex else for i, v in ipairs(t) do if v == elementOrIndex then index = i break end end end if index then local movedElement = table.remove(t, index) table.insert(t, newPosition, movedElement) end end function tableShallowCopy(t) local t2 = {} for k,v in pairs(t) do t2[k] = v end return t2 end