diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-01 18:39:20 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-01 18:39:20 +0200 |
commit | 85629985b71035608a37ba3bde86968481490d46 (patch) | |
tree | 5970b7cc5eb33369ad8ee0337884e781fba1dfea /runtime | |
parent | e8f5ec0d30b629d7166f0ad03434065d8bc822df (diff) | |
download | vim-git-85629985b71035608a37ba3bde86968481490d46.tar.gz |
patch 8.2.0878: no reduce() functionv8.2.0878
Problem: No reduce() function.
Solution: Add a reduce() function. (closes #5481)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 19547305e..7b85acd55 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2679,6 +2679,8 @@ readdir({dir} [, {expr}]) List file names in {dir} selected by {expr} readdirex({dir} [, {expr}]) List file info in {dir} selected by {expr} readfile({fname} [, {type} [, {max}]]) List get list of lines from file {fname} +reduce({object}, {func} [, {initial}]) + any reduce {object} using {func} reg_executing() String get the executing register name reg_recording() String get the recording register name reltime([{start} [, {end}]]) List get time value @@ -7965,6 +7967,26 @@ readfile({fname} [, {type} [, {max}]]) Can also be used as a |method|: > GetFileName()->readfile() +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. + + {initial} is the initial result. When omitted, the first item + in {object} is used and {func} is first called for the second + item. If {initial} is not given and {object} is empty no + result can be computed, an E998 error is given. + + Examples: > + 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 }) +< + Can also be used as a |method|: > + echo mylist->reduce({ acc, val -> acc + val }, 0) + + reg_executing() *reg_executing()* Returns the single letter name of the register being executed. Returns an empty string when no register is being executed. |