Mercurial > vim
comparison runtime/doc/eval.txt @ 26638:6fd15d82e898 v8.2.3848
patch 8.2.3848: cannot use reduce() for a string
Commit: https://github.com/vim/vim/commit/0ccb5842f5fb103763d106c7aa364d758343c35a
Author: rbtnn <naru123456789@gmail.com>
Date: Sat Dec 18 18:33:46 2021 +0000
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 https://github.com/vim/vim/issues/9366)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 18 Dec 2021 19:45:03 +0100 |
parents | 3a63b1e4a6f4 |
children | 7c055fdd6200 |
comparison
equal
deleted
inserted
replaced
26637:eeac85e187e7 | 26638:6fd15d82e898 |
---|---|
8957 Can also be used as a |method|: > | 8957 Can also be used as a |method|: > |
8958 GetFileName()->readfile() | 8958 GetFileName()->readfile() |
8959 | 8959 |
8960 reduce({object}, {func} [, {initial}]) *reduce()* *E998* | 8960 reduce({object}, {func} [, {initial}]) *reduce()* *E998* |
8961 {func} is called for every item in {object}, which can be a | 8961 {func} is called for every item in {object}, which can be a |
8962 |List| or a |Blob|. {func} is called with two arguments: the | 8962 |String|, |List| or a |Blob|. {func} is called with two arguments: |
8963 result so far and current item. After processing all items | 8963 the result so far and current item. After processing all |
8964 the result is returned. | 8964 items the result is returned. |
8965 | 8965 |
8966 {initial} is the initial result. When omitted, the first item | 8966 {initial} is the initial result. When omitted, the first item |
8967 in {object} is used and {func} is first called for the second | 8967 in {object} is used and {func} is first called for the second |
8968 item. If {initial} is not given and {object} is empty no | 8968 item. If {initial} is not given and {object} is empty no |
8969 result can be computed, an E998 error is given. | 8969 result can be computed, an E998 error is given. |
8970 | 8970 |
8971 Examples: > | 8971 Examples: > |
8972 echo reduce([1, 3, 5], { acc, val -> acc + val }) | 8972 echo reduce([1, 3, 5], { acc, val -> acc + val }) |
8973 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') | 8973 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') |
8974 echo reduce(0z1122, { acc, val -> 2 * acc + val }) | 8974 echo reduce(0z1122, { acc, val -> 2 * acc + val }) |
8975 echo reduce('xyz', { acc, val -> acc .. ',' .. val }) | |
8975 < | 8976 < |
8976 Can also be used as a |method|: > | 8977 Can also be used as a |method|: > |
8977 echo mylist->reduce({ acc, val -> acc + val }, 0) | 8978 echo mylist->reduce({ acc, val -> acc + val }, 0) |
8978 | 8979 |
8979 | 8980 |