From 4c5006d1e7c55c11417b77ce129f6730f4b54604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 15 Feb 2025 18:04:00 +0300 Subject: [PATCH] add predicate and reduce function doc --- data/scripts/types/list.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/data/scripts/types/list.lua b/data/scripts/types/list.lua index 47f6525..3a06476 100644 --- a/data/scripts/types/list.lua +++ b/data/scripts/types/list.lua @@ -68,16 +68,23 @@ function List:pop() return table.remove(self, #self) end ----Reduce. ----@param f function called with element, accumulator, index ----@param init any initial value of accumulator +---Removes the first element in the list and returns it. ---@return any +function List:pop_front() + return table.remove(self, 1) +end + +---Reduce. +---@generic T +---@param f fun(element: any, accumulator: T, index: integer): T +---@param init T|nil initial value of accumulator +---@return T function List:reduce(f, init) return reduce(self, f, init) end ---Returns a new List of all elements of this list that match the predicate function. ----@param predicate function called with element +---@param predicate fun(element: any): boolean ---@return List function List:filter(predicate) return filter(self, predicate)