diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-04-19 08:23:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 08:23:42 -0600 |
commit | 0ad5237162a05f0f04c74eab1961166f4f74254b (patch) | |
tree | ffc7297809337b2178b938d955361d07634bd4c6 /runtime/doc | |
parent | 0d7bed34a29ef1add5d225a6809882fa6dce49d9 (diff) | |
parent | 94894068794dbb99804cda689b6c37e70376c8ca (diff) | |
download | rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.tar.gz rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.tar.bz2 rneovim-0ad5237162a05f0f04c74eab1961166f4f74254b.zip |
Merge pull request #23198 from gpanders/iter-fix
fix(iter): allow table values in iterator pipelines
Diffstat (limited to 'runtime/doc')
-rw-r--r-- | runtime/doc/lua.txt | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 60067f1bc3..8e68e9a792 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -3037,6 +3037,19 @@ Iter:find({self}, {f}) *Iter:find()* Iter:fold({self}, {init}, {f}) *Iter:fold()* Fold an iterator or table into a single value. + Examples: > + + -- Create a new table with only even values + local t = { a = 1, b = 2, c = 3, d = 4 } + local it = vim.iter(t) + it:filter(function(k, v) return v % 2 == 0 end) + it:fold({}, function(t, k, v) + t[k] = v + return t + end) + -- { b = 2, d = 4 } +< + Parameters: ~ • {init} any Initial value of the accumulator. • {f} function(acc:any, ...):A Accumulation function. @@ -3297,9 +3310,7 @@ Iter:totable({self}) *Iter:totable()* The resulting table depends on the initial source in the iterator pipeline. List-like tables and function iterators will be collected into a list-like table. If multiple values are returned from the final stage in - the iterator pipeline, each value will be included in a table. If a - map-like table was used as the initial source, then a map-like table is - returned. + the iterator pipeline, each value will be included in a table. Examples: >lua @@ -3310,9 +3321,13 @@ Iter:totable({self}) *Iter:totable()* -- { { 1, 2 }, { 2, 4 }, { 3, 6 } } vim.iter({ a = 1, b = 2, c = 3 }):filter(function(k, v) return v % 2 ~= 0 end):totable() - -- { a = 1, c = 3 } + -- { { 'a', 1 }, { 'c', 3 } } < + The generated table is a list-like table with consecutive, numeric + indices. To create a map-like table with arbitrary keys, use + |Iter:fold()|. + Return: ~ (table) |