forked from aniani/vim
patch 8.2.3849: functions implementing reduce and map are too long
Problem: Functions implementing reduce and map are too long.
Solution: Use a function for each type of value. Add a few more test cases
and add to the help. (Yegappan Lakshmanan, closes #9370)
This commit is contained in:
committed by
Bram Moolenaar
parent
0ccb5842f5
commit
389b72196e
@@ -4893,7 +4893,8 @@ filter({expr1}, {expr2}) *filter()*
|
|||||||
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
|
of the current item and for a |List| |v:key| has the index of
|
||||||
the current item. For a |Blob| |v:key| has the index of the
|
the current item. For a |Blob| |v:key| has the index of the
|
||||||
current byte.
|
current byte. For a |String| |v:key| has the index of the
|
||||||
|
current character.
|
||||||
Examples: >
|
Examples: >
|
||||||
call filter(mylist, 'v:val !~ "OLD"')
|
call filter(mylist, 'v:val !~ "OLD"')
|
||||||
< Removes the items where "OLD" appears. >
|
< Removes the items where "OLD" appears. >
|
||||||
@@ -7588,7 +7589,8 @@ map({expr1}, {expr2}) *map()*
|
|||||||
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
|
of the current item and for a |List| |v:key| has the index of
|
||||||
the current item. For a |Blob| |v:key| has the index of the
|
the current item. For a |Blob| |v:key| has the index of the
|
||||||
current byte.
|
current byte. For a |String| |v:key| has the index of the
|
||||||
|
current character.
|
||||||
Example: >
|
Example: >
|
||||||
:call map(mylist, '"> " . v:val . " <"')
|
:call map(mylist, '"> " . v:val . " <"')
|
||||||
< This puts "> " before and " <" after each item in "mylist".
|
< This puts "> " before and " <" after each item in "mylist".
|
||||||
@@ -8959,9 +8961,9 @@ readfile({fname} [, {type} [, {max}]])
|
|||||||
|
|
||||||
reduce({object}, {func} [, {initial}]) *reduce()* *E998*
|
reduce({object}, {func} [, {initial}]) *reduce()* *E998*
|
||||||
{func} is called for every item in {object}, which can be a
|
{func} is called for every item in {object}, which can be a
|
||||||
|String|, |List| or a |Blob|. {func} is called with two arguments:
|
|String|, |List| or a |Blob|. {func} is called with two
|
||||||
the result so far and current item. After processing all
|
arguments: the result so far and current item. After
|
||||||
items the result is returned.
|
processing all items the result is returned.
|
||||||
|
|
||||||
{initial} is the initial result. When omitted, the first item
|
{initial} is the initial result. When omitted, the first item
|
||||||
in {object} is used and {func} is first called for the second
|
in {object} is used and {func} is first called for the second
|
||||||
|
|||||||
1040
src/list.c
1040
src/list.c
File diff suppressed because it is too large
Load Diff
@@ -994,6 +994,9 @@ func Test_reduce()
|
|||||||
call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1253:')
|
call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1253:')
|
||||||
call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
|
call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
|
||||||
call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
|
call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
|
||||||
|
call assert_fails("call reduce('abc', { a, v -> a10}, '')", 'E121:')
|
||||||
|
call assert_fails("call reduce(0z01, { a, v -> a10}, 1)", 'E121:')
|
||||||
|
call assert_fails("call reduce([1], { a, v -> a10}, '')", 'E121:')
|
||||||
|
|
||||||
let g:lut = [1, 2, 3, 4]
|
let g:lut = [1, 2, 3, 4]
|
||||||
func EvilRemove()
|
func EvilRemove()
|
||||||
|
|||||||
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3849,
|
||||||
/**/
|
/**/
|
||||||
3848,
|
3848,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user