aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-12-05 18:35:22 -0800
committerGitHub <noreply@github.com>2023-12-05 18:35:22 -0800
commit5b40a1c09dda83275784053b325ad16626fc55f2 (patch)
treed88817c9bc73998318922f37b1057a8e446bf97e /runtime
parentcc38086039853d53157b30fec41babb148399038 (diff)
downloadrneovim-5b40a1c09dda83275784053b325ad16626fc55f2.tar.gz
rneovim-5b40a1c09dda83275784053b325ad16626fc55f2.tar.bz2
rneovim-5b40a1c09dda83275784053b325ad16626fc55f2.zip
feat(lua): implement Iter:join() (#26416)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/lua.txt13
-rw-r--r--runtime/lua/vim/iter.lua12
2 files changed, 25 insertions, 0 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index a35d70cae8..f7f722bc0e 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -3410,6 +3410,19 @@ Iter:fold({init}, {f}) *Iter:fold()*
Return: ~
any
+Iter:join({delim}) *Iter:join()*
+ Collect the iterator into a delimited string.
+
+ Each element in the iterator is joined into a string separated by {delim}.
+
+ Consumes the iterator.
+
+ Parameters: ~
+ • {delim} (string) Delimiter
+
+ Return: ~
+ (string)
+
Iter:last() *Iter:last()*
Drains the iterator and returns the last item.
diff --git a/runtime/lua/vim/iter.lua b/runtime/lua/vim/iter.lua
index 874bdfb437..e9c2b66bf2 100644
--- a/runtime/lua/vim/iter.lua
+++ b/runtime/lua/vim/iter.lua
@@ -356,6 +356,18 @@ function ListIter.totable(self)
return self._table
end
+--- Collect the iterator into a delimited string.
+---
+--- Each element in the iterator is joined into a string separated by {delim}.
+---
+--- Consumes the iterator.
+---
+--- @param delim string Delimiter
+--- @return string
+function Iter.join(self, delim)
+ return table.concat(self:totable(), delim)
+end
+
--- Folds ("reduces") an iterator into a single value.
---
--- Examples: