ducks choose the closest feed
This commit is contained in:
@ -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
|
Reference in New Issue
Block a user