diff options
author | rbtnn <naru123456789@gmail.com> | 2021-12-18 18:33:46 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-18 18:33:46 +0000 |
commit | 0ccb5842f5fb103763d106c7aa364d758343c35a (patch) | |
tree | 76ea36f2abf5035e3695132e0cc5b59e2e9a325c /runtime/doc/eval.txt | |
parent | 605ec91e5a7330d61be313637e495fa02a6dc264 (diff) | |
download | vim-git-0ccb5842f5fb103763d106c7aa364d758343c35a.tar.gz |
patch 8.2.3848: cannot use reduce() for a stringv8.2.3848
Problem: Cannot use reduce() for a string.
Solution: Make reduce() work with a string. (Naruhiko Nishino, closes #9366)
Diffstat (limited to 'runtime/doc/eval.txt')
-rw-r--r-- | runtime/doc/eval.txt | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 6765bdcf7..d54523f96 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -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) |