summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/iter.lua
AgeCommit message (Collapse)AuthorFiles
2026-03-11docs: api, messages, lsp, trustJustin M. Keyes1
gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
2026-02-12feat(iter): peek(), skip(predicate) for non-list iterators #37604Elijah Koulaxis1
Problem: Iter:peek() only works if the iterator is a |list-iterator| (internally, an `ArrayIter`). However, it is possible to implement :peek() support for any iterator. Solution: - add `_peeked` buffer for lookahead without actually consuming values - `peek()` now works for function, pairs(), and array iterators - `skip(predicate)` stops at the first non matching element without consuming it - keep existing optimized behavior for `ArrayIter` to maintain backward compatibility - use `pack`/`unpack` to support iterators that return multiple values
2026-02-10feat(lua): add `Iter:unique()` (#37592)Olivia Kinnear1
2025-07-22fix(iter): ArrayIter:last returns nil when filtered to empty #34697glepnir1
Problem: After filtering out all elements, ArrayIter:last still returns a stale element. Solution: Add check for self._head == self._tail and return nil early. Fix #34696
2025-07-03feat(runtime): accept predicates in take and skip (#34657)Mart-Mihkel Aun1
Make `vim.iter():take()` and `vim.iter():skip()` optionally accept predicates to enable takewhile and skipwhile patterns used in functional programming.
2025-03-15docs: miscdundargoc1
Co-authored-by: Au. <acehinnnqru@gmail.com> Co-authored-by: Daniel Rainer <daniel.rainer@localhost> Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com> Co-authored-by: Lewis Russell <lewis6991@gmail.com> Co-authored-by: Luuk van Baal <luukvbaal@gmail.com> Co-authored-by: Pierre Barbin <pierre@heitzsystem.com> Co-authored-by: Riley Bruins <ribru17@hotmail.com> Co-authored-by: Yinzuo Jiang <jiangyinzuo@foxmail.com> Co-authored-by: phanium <91544758+phanen@users.noreply.github.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-09-01docs: misc #28970Justin M. Keyes1
2024-06-11fix(types): use vararg return type annotationWill Hopkins1
build(types): allow vararg returns in function types
2024-05-17fix(vim.iter): enable optimizations for arrays (lists with holes) (#28781)Gregory Anders1
The optimizations that vim.iter uses for array-like tables don't require that the source table has no holes. The only thing that needs to change is the determination if a table is "list-like": rather than requiring consecutive, integer keys, we can simply test for (positive) integer keys only, and remove any holes in the original array when we make a copy for the iterator.
2024-05-15docs: misc (#28609)dundargoc1
Closes https://github.com/neovim/neovim/issues/28484. Closes https://github.com/neovim/neovim/issues/28719. Co-authored-by: Chris <crwebb85@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Jake B <16889000+jakethedev@users.noreply.github.com> Co-authored-by: Jonathan Raines <jonathan.s.raines@gmail.com> Co-authored-by: Yi Ming <ofseed@foxmail.com> Co-authored-by: Zane Dufour <zane@znd4.me> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-05-13refactor(lua): remove deprecated features #28725Justin M. Keyes1
2024-04-30docs: misc #24163Justin M. Keyes1
- Also delete old perl scripts which are not used since 8+ years ago. fix #23251 fix #27367 ref https://github.com/neovim/neovim/issues/2252#issuecomment-1902662577 Helped-by: Daniel Kongsgaard <dakongsgaard@gmail.com> Co-authored-by: Kevin Pham <keevan.pham@gmail.com>
2024-04-26refactor(vim.iter)!: rename xxback() => rxx() #28503Justin M. Keyes1
Problem: vim.iter has both `rfind()` and various `*back()` methods, which work in "reverse" or "backwards" order. It's inconsistent to have both kinds of names, and "back" is fairly uncommon (rust) compared to python (rfind, rstrip, rsplit, …). Solution: - Remove `nthback()` and let `nth()` take a negative index. - Because `rnth()` looks pretty obscure, and because it's intuitive for a function named `nth()` to take negative indexes. - Rename `xxback()` methods to `rxx()`. - This informally groups the "list-iterator" functions under a common `r` prefix, which helps discoverability. - Rename `peekback()` to `pop()`, in duality with the existing `peek`.
2024-04-19refactor(vim.iter)!: remove vim.iter.map/filter/totable #26138Justin M. Keyes1
Problem: The use-case for the convenience functions vim.iter.map(), vim.iter.filter(), vim.iter.totable() is not clear. Solution: Drop them for now. We can revisit after 0.10 release.
2024-03-23fix(vim.iter): use correct cmp function when truncating tail in `take` (#27998)Calvin Bochulak1
2024-03-09docs: support inline markdownLewis Russell1
- Tags are now created with `[tag]()` - References are now created with `[tag]` - Code spans are no longer wrapped
2024-03-06fix(types): move type annotation for `IterMod`Will Hopkins1
2024-03-06refactor(types): more fixes (2)Lewis Russell1
2024-03-01docs: improve/add documentation of Lua typesLewis Russell1
- Added `@inlinedoc` so single use Lua types can be inlined into the functions docs. E.g. ```lua --- @class myopts --- @inlinedoc --- --- Documentation for some field --- @field somefield integer --- @param opts myOpts function foo(opts) end ``` Will be rendered as ``` foo(opts) Parameters: - {opts} (table) Object with the fields: - somefield (integer) Documentation for some field ``` - Marked many classes with with `@nodoc` or `(private)`. We can eventually introduce these when we want to.
2024-02-27feat(docs): replace lua2dox.luaLewis Russell1
Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
2024-01-18docs(vim.iter): correct `bool` to `boolean` (#27018)notomo1
2024-01-11fix(doc): improve doc generation of types using lpegLewis Russell1
Added a lpeg grammar for LuaCATS and use it in lua2dox.lua
2024-01-10feat(vim.iter): add Iter:flatten (#26786)JD1
Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Jongwook Choi <wookayin@gmail.com>
2023-12-30refactor: fix luals warningsdundargoc1
2023-12-12feat(iter): add `Iter.take` (#26525)Will Hopkins1
2023-12-05feat(lua): implement Iter:join() (#26416)Gregory Anders1
2023-11-25docs: vim.iter #26169Justin M. Keyes1
closes #24141 closes #24746
2023-09-13feat(vimdoc): support Markdown code blocks (#25127)Gregory Anders1
Support Markdown code blocks in addition to <pre> blocks in Doxygen doc comments. Update doc comments in iter.lua as a test.
2023-08-09fix(iter): make pipeline termination conditions consistent (#24614)Gregory Anders1
If an iterator pipeline stage returns nil as its first return value, the other return values are ignored and it is treated as if that stage returned only nil (the semantics of returning nil are different between different stages). This is consistent with how for loops work in Lua more generally, where the for loop breaks when the first return value from the function iterator is nil (see :h for-in for details).
2023-08-03docs: miscJustin M. Keyes1
Co-authored-by: Kevin Pham <keevan.pham@gmail.com>
2023-07-18docs(lua): more improvements (#24387)Lewis Russell1
* docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2023-07-17docs(lua): change *lua-foo* -> *vim.foo*Lewis Russell1
2023-06-25fix(docs): vimdoc syntax errorsJustin M. Keyes1
gen_help_html: truncate parse-error sample text
2023-06-19docs #22363Justin M. Keyes1
Co-authored by: zeertzjq <zeertzjq@outlook.com> Co-authored by: Steven Todd McIntyre II <114119064+stmii@users.noreply.github.com> Co-authored by: nobe4 <nobe4@users.noreply.github.com> - docs: mention --luadev-mod to run with lua runtime files When changing a lua file in the ./runtime folder, a new contributor might expect changes to be applied to the built Neovim binary.
2023-06-10feat(lua): use callable table as iterator in vim.iter (#23957)Mathias Fußenegger1
A table passed to `vim.iter` can be a class instance with a `__call` implementation for the iterator protocol.
2023-06-03perf(iter): make ListIter.totable more efficient (#23714)Lewis Russell1
2023-06-03docs(iter): add emmylua type to iter module (#23845)Sebastian Lyng Johansen1
2023-06-02docs: small fixes (#23619)dundargoc1
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com> Co-authored-by: Gustavo Ferreira <gustavo.ferreira@imaginecurve.com> Co-authored-by: Kai Moschcau <mail@kmoschcau.de> Co-authored-by: Lampros <hauahx@gmail.com>
2023-04-28perf(iter): reduce number of table allocationsGregory Anders1
Packing and unpacking return values impairs performance considerably. In an attempt to avoid creating tables as much as possible we can instead pass return values between functions (which does not require knowing the number of values a function might return). This makes the code more complex, but improves benchmark numbers non-trivially.
2023-04-25refactor(iter): move helper functions under vim.iterGregory Anders1
vim.iter is now both a function and a module (similar to vim.version).
2023-04-21refactor(iter): use metatable as packed table tag (#23254)Gregory Anders1
This is a more robust method for tagging a packed table as it completely eliminates the possibility of mistaking an actual table key as the packed table tag.
2023-04-19fix(iter): remove special case totable for map-like tablesGregory Anders1
This was originally meant as a convenience but prevents possible functionality. For example: -- Get the keys of the table with even values local t = { a = 1, b = 2, c = 3, d = 4 } vim.iter(t):map(function(k, v) if v % 2 == 0 then return k end end):totable() The example above would not work, because the map() function returns only a single value, and cannot be converted back into a table (there are many such examples like this). Instead, to convert an iterator into a map-like table, users can use fold(): vim.iter(t):fold({}, function(t, k, v) t[k] = v return t end)
2023-04-19fix(iter): add tag to packed tableGregory Anders1
If pack() is called with a single value, it does not create a table; it simply returns the value it is passed. When unpack is called with a table argument, it interprets that table as a list of values that were packed together into a table. This causes a problem when the single value being packed is _itself_ a table. pack() will not place it into another table, but unpack() sees the table argument and tries to unpack it. To fix this, we add a simple "tag" to packed table values so that unpack() only attempts to unpack tables that have this tag. Other tables are left alone. The tag is simply the length of the table.
2023-04-17feat(lua): add vim.iter (#23029)Gregory Anders1
vim.iter wraps a table or iterator function into an `Iter` object with methods such as `filter`, `map`, and `fold` which can be chained to produce iterator pipelines that do not create new tables at each step.