1
0
forked from aniani/vim

patch 8.2.3848: cannot use reduce() for a string

Problem:    Cannot use reduce() for a string.
Solution:   Make reduce() work with a string. (Naruhiko Nishino, closes #9366)
This commit is contained in:
rbtnn
2021-12-18 18:33:46 +00:00
committed by Bram Moolenaar
parent 605ec91e5a
commit 0ccb5842f5
9 changed files with 149 additions and 40 deletions

View File

@@ -8959,9 +8959,9 @@ readfile({fname} [, {type} [, {max}]])
reduce({object}, {func} [, {initial}]) *reduce()* *E998*
{func} is called for every item in {object}, which can be a
|List| or a |Blob|. {func} is called with two arguments: the
result so far and current item. After processing all items
the result is returned.
|String|, |List| or a |Blob|. {func} is called with two arguments:
the result so far and current item. After processing all
items the result is returned.
{initial} is the initial result. When omitted, the first item
in {object} is used and {func} is first called for the second
@@ -8972,6 +8972,7 @@ reduce({object}, {func} [, {initial}]) *reduce()* *E998*
echo reduce([1, 3, 5], { acc, val -> acc + val })
echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
echo reduce(0z1122, { acc, val -> 2 * acc + val })
echo reduce('xyz', { acc, val -> acc .. ',' .. val })
<
Can also be used as a |method|: >
echo mylist->reduce({ acc, val -> acc + val }, 0)