Skip to main content
Module

x/ddc_vim/deps.ts>fn.map

Dark deno-powered completion framework for neovim/Vim8
Go to Latest
function fn.map
import { fn } from "https://deno.land/x/ddc_vim@v2.3.0/deps.ts";
const { map } = fn;

{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. This is required when using Vim9 script. {expr2} must be a |string| or |Funcref|. If {expr2} is a |string|, inside {expr2} |v:val| has the value of the current item. For a |Dictionary| |v:key| has the key of the current item and for a |List| |v:key| has the index of the current item. Example: :call map(mylist, '"> " . v:val . " <"') This puts "> " before and " <" after each item in "mylist". Note that {expr2} is the result of an expression and is then used as an expression again. Often it is good to use a |literal-string| to avoid having to double backslashes. You still have to double ' quotes If {expr2} is a |Funcref| it is called with two arguments: 1. The key or the index of the current item. 2. the value of the current item. The function must return the new value of the item. Example that changes each value by "key-value": func KeyValue(key, val) return a:key . '-' . a:val endfunc call map(myDict, function('KeyValue')) It is shorter when using a |lambda|: call map(myDict, {key, val -> key . '-' . val}) If you do not use "val" you can leave it out: call map(myDict, {key -> 'item: ' . key}) If you do not use "key" you can use a short name: call map(myDict, {_, val -> 'item: ' . val}) The operation is done in-place. If you want a |List| or |Dictionary| to remain unmodified make a copy first: :let tlist = map(copy(mylist), ' v:val . "\t"') Returns {expr1}, the |List|, |Blob| or |Dictionary| that was filtered. When an error is encountered while evaluating {expr2} no further items in {expr1} are processed. When {expr2} is a Funcref errors inside a function are ignored, unless it was defined with the "abort" flag. Can also be used as a |method|: mylist->map(expr2)

Parameters

denops: Denops
expr1: unknown
expr2: unknown

Returns

Promise<unknown>