ducks choose the closest feed

This commit is contained in:
2025-02-15 18:03:43 +03:00
parent 954277688f
commit 6a952a221b
3 changed files with 38 additions and 13 deletions

View File

@ -126,4 +126,33 @@ function List:is_empty()
return #self == 0
end
---Returns a (shallow) copy of this list.
---@return List
function List:copy()
return List.create(self)
end
---Returns a new copy of this list with the order of the elements shuffled around.
---@return List
function List:shuffled()
-- https://gist.github.com/Uradamus/10323382
local list = self:copy()
for i = #list, 2, -1 do
local j = math.random(i)
list[i], list[j] = list[j], list[i]
end
return list
end
---Returns a sorted copy of this list.
---@param f? fun(a: any, b: any)
---@return List
function List:sorted(f)
local list = self:copy()
table.sort(list, f)
return list
end
return List