mirror of
https://github.com/neovim/neovim.git
synced 2026-02-11 14:28:48 +00:00
docs: manpage, keycodes, json
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user