diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2025-09-06 13:49:19 -0400 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2025-09-13 22:49:50 -0400 |
| commit | db67607201a55d7a2d578c6c7661c8e6770f5b2f (patch) | |
| tree | 638119e2bd88b8f6fee4c3938c3c32b9a8c7abb1 /runtime/lua/vim/shared.lua | |
| parent | 2f78ff816b03661b5f74d0624e973eaca0d64ef1 (diff) | |
docs: manpage, keycodes, json
Diffstat (limited to 'runtime/lua/vim/shared.lua')
| -rw-r--r-- | runtime/lua/vim/shared.lua | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 014b64c18b..8c55081050 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -244,20 +244,21 @@ function vim.tbl_values(t) return values end ---- Apply a function to all values of a table. +--- Applies function `fn` to all values of table `t`, in `pairs()` iteration order (which is not +--- guaranteed to be stable, even when the data doesn't change). --- ---@generic T ----@param func fun(value: T): any Function +---@param fn fun(value: T): any Function ---@param t table<any, T> Table ---@return table : Table of transformed values -function vim.tbl_map(func, t) - vim.validate('func', func, 'callable') +function vim.tbl_map(fn, t) + vim.validate('fn', fn, 'callable') vim.validate('t', t, 'table') --- @cast t table<any,any> local rettab = {} --- @type table<any,any> for k, v in pairs(t) do - rettab[k] = func(v) + rettab[k] = fn(v) end return rettab end @@ -265,17 +266,17 @@ end --- Filter a table using a predicate function --- ---@generic T ----@param func fun(value: T): boolean (function) Function +---@param fn fun(value: T): boolean (function) Function ---@param t table<any, T> (table) Table ---@return T[] : Table of filtered values -function vim.tbl_filter(func, t) - vim.validate('func', func, 'callable') +function vim.tbl_filter(fn, t) + vim.validate('fn', fn, 'callable') vim.validate('t', t, 'table') --- @cast t table<any,any> local rettab = {} --- @type table<any,any> for _, entry in pairs(t) do - if func(entry) then + if fn(entry) then rettab[#rettab + 1] = entry end end |
