comparison runtime/doc/eval.txt @ 26640:7c055fdd6200 v8.2.3849

patch 8.2.3849: functions implementing reduce and map are too long Commit: https://github.com/vim/vim/commit/389b72196e6aaeafe3f907c73d271f2c6b931140 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Dec 19 10:35:15 2021 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Dec 2021 11:45:03 +0100
parents 6fd15d82e898
children f0d7cb510ce3
comparison
equal deleted inserted replaced
26639:bede9e63f1a7 26640:7c055fdd6200
4891 4891
4892 If {expr2} is a |string|, inside {expr2} |v:val| has the value 4892 If {expr2} is a |string|, inside {expr2} |v:val| has the value
4893 of the current item. For a |Dictionary| |v:key| has the key 4893 of the current item. For a |Dictionary| |v:key| has the key
4894 of the current item and for a |List| |v:key| has the index of 4894 of the current item and for a |List| |v:key| has the index of
4895 the current item. For a |Blob| |v:key| has the index of the 4895 the current item. For a |Blob| |v:key| has the index of the
4896 current byte. 4896 current byte. For a |String| |v:key| has the index of the
4897 current character.
4897 Examples: > 4898 Examples: >
4898 call filter(mylist, 'v:val !~ "OLD"') 4899 call filter(mylist, 'v:val !~ "OLD"')
4899 < Removes the items where "OLD" appears. > 4900 < Removes the items where "OLD" appears. >
4900 call filter(mydict, 'v:key >= 8') 4901 call filter(mydict, 'v:key >= 8')
4901 < Removes the items with a key below 8. > 4902 < Removes the items with a key below 8. >
7586 7587
7587 If {expr2} is a |String|, inside {expr2} |v:val| has the value 7588 If {expr2} is a |String|, inside {expr2} |v:val| has the value
7588 of the current item. For a |Dictionary| |v:key| has the key 7589 of the current item. For a |Dictionary| |v:key| has the key
7589 of the current item and for a |List| |v:key| has the index of 7590 of the current item and for a |List| |v:key| has the index of
7590 the current item. For a |Blob| |v:key| has the index of the 7591 the current item. For a |Blob| |v:key| has the index of the
7591 current byte. 7592 current byte. For a |String| |v:key| has the index of the
7593 current character.
7592 Example: > 7594 Example: >
7593 :call map(mylist, '"> " . v:val . " <"') 7595 :call map(mylist, '"> " . v:val . " <"')
7594 < This puts "> " before and " <" after each item in "mylist". 7596 < This puts "> " before and " <" after each item in "mylist".
7595 7597
7596 Note that {expr2} is the result of an expression and is then 7598 Note that {expr2} is the result of an expression and is then
8957 Can also be used as a |method|: > 8959 Can also be used as a |method|: >
8958 GetFileName()->readfile() 8960 GetFileName()->readfile()
8959 8961
8960 reduce({object}, {func} [, {initial}]) *reduce()* *E998* 8962 reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8961 {func} is called for every item in {object}, which can be a 8963 {func} is called for every item in {object}, which can be a
8962 |String|, |List| or a |Blob|. {func} is called with two arguments: 8964 |String|, |List| or a |Blob|. {func} is called with two
8963 the result so far and current item. After processing all 8965 arguments: the result so far and current item. After
8964 items the result is returned. 8966 processing all items the result is returned.
8965 8967
8966 {initial} is the initial result. When omitted, the first item 8968 {initial} is the initial result. When omitted, the first item
8967 in {object} is used and {func} is first called for the second 8969 in {object} is used and {func} is first called for the second
8968 item. If {initial} is not given and {object} is empty no 8970 item. If {initial} is not given and {object} is empty no
8969 result can be computed, an E998 error is given. 8971 result can be computed, an E998 error is given.