From 8cbb2477cf70ea29105e3df17308e6d6a067c8e6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Aug 2023 09:43:00 +0800 Subject: vim-patch:8.2.1969: Vim9: map() may change the list or dict item type Problem: Vim9: map() may change the list or dict item type. Solution: Add mapnew(). https://github.com/vim/vim/commit/ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed Co-authored-by: Bram Moolenaar --- src/nvim/eval.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/eval.lua') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 8a36509f9a..8bfea4938b 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -6053,6 +6053,8 @@ M.funcs = { {expr1} must be a |List|, |Blob| or |Dictionary|. Replace each item in {expr1} with the result of evaluating {expr2}. For a |Blob| each byte is replaced. + If the item type changes you may want to use |mapnew()| to + create a new List or Dictionary. {expr2} must be a |string| or |Funcref|. @@ -6215,6 +6217,18 @@ M.funcs = { params = { { 'name', 'string' }, { 'mode', 'string' }, { 'abbr', 'any' } }, signature = 'mapcheck({name} [, {mode} [, {abbr}]])', }, + mapnew = { + args = 2, + base = 1, + desc = [=[ + Like |map()| but instead of replacing items in {expr1} a new + List or Dictionary is created and returned. {expr1} remains + unchanged. + ]=], + name = 'mapnew', + params = { { 'expr1', 'any' }, { 'expr2', 'any' } }, + signature = 'mapnew({expr1}, {expr2})', + }, mapset = { args = 3, base = 1, -- cgit