Replace each item in {expr} with the result of evaluating
{string}.
Inside {string} |v:val| has the value of the current item.
- For a |Dictionary| |v:key| has the key 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".
int todo;
char_u *ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
int save_did_emsg;
+ int index = 0;
if (argvars[0].v_type == VAR_LIST)
{
save_did_emsg = did_emsg;
did_emsg = FALSE;
+ prepare_vimvar(VV_KEY, &save_key);
if (argvars[0].v_type == VAR_DICT)
{
- prepare_vimvar(VV_KEY, &save_key);
vimvars[VV_KEY].vv_type = VAR_STRING;
ht = &d->dv_hashtab;
}
}
hash_unlock(ht);
-
- restore_vimvar(VV_KEY, &save_key);
}
else
{
+ vimvars[VV_KEY].vv_type = VAR_NUMBER;
+
for (li = l->lv_first; li != NULL; li = nli)
{
if (tv_check_lock(li->li_tv.v_lock, ermsg))
break;
nli = li->li_next;
+ vimvars[VV_KEY].vv_nr = index;
if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
|| did_emsg)
break;
if (!map && rem)
listitem_remove(l, li);
+ ++index;
}
}
+ restore_vimvar(VV_KEY, &save_key);
restore_vimvar(VV_VAL, &save_val);
did_emsg |= save_did_emsg;