mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(vim.iter)!: remove vim.iter.map/filter/totable #26138
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.
This commit is contained in:
parent
9319d97679
commit
18da6964cc
@ -3871,27 +3871,6 @@ Examples: >lua
|
|||||||
-- { "a", "b" }
|
-- { "a", "b" }
|
||||||
<
|
<
|
||||||
|
|
||||||
In addition to the |vim.iter()| function, the |vim.iter| module provides
|
|
||||||
convenience functions like |vim.iter.filter()| and |vim.iter.totable()|.
|
|
||||||
|
|
||||||
|
|
||||||
filter({f}, {src}) *vim.iter.filter()*
|
|
||||||
Filters a table or other |iterable|. >lua
|
|
||||||
-- Equivalent to:
|
|
||||||
vim.iter(src):filter(f):totable()
|
|
||||||
<
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
• {f} (`fun(...):boolean`) Filter function. Accepts the current
|
|
||||||
iterator or table values as arguments and returns true if those
|
|
||||||
values should be kept in the final table
|
|
||||||
• {src} (`table|function`) Table or iterator function to filter
|
|
||||||
|
|
||||||
Return: ~
|
|
||||||
(`table`)
|
|
||||||
|
|
||||||
See also: ~
|
|
||||||
• |Iter:filter()|
|
|
||||||
|
|
||||||
Iter:all({pred}) *Iter:all()*
|
Iter:all({pred}) *Iter:all()*
|
||||||
Returns true if all items in the iterator match the given predicate.
|
Returns true if all items in the iterator match the given predicate.
|
||||||
@ -4319,36 +4298,6 @@ Iter:totable() *Iter:totable()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
(`table`)
|
(`table`)
|
||||||
|
|
||||||
map({f}, {src}) *vim.iter.map()*
|
|
||||||
Maps a table or other |iterable|. >lua
|
|
||||||
-- Equivalent to:
|
|
||||||
vim.iter(src):map(f):totable()
|
|
||||||
<
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
• {f} (`fun(...): any?`) Map function. Accepts the current iterator
|
|
||||||
or table values as arguments and returns one or more new
|
|
||||||
values. Nil values are removed from the final table.
|
|
||||||
• {src} (`table|function`) Table or iterator function to filter
|
|
||||||
|
|
||||||
Return: ~
|
|
||||||
(`table`)
|
|
||||||
|
|
||||||
See also: ~
|
|
||||||
• |Iter:map()|
|
|
||||||
|
|
||||||
totable({f}) *vim.iter.totable()*
|
|
||||||
Collects an |iterable| into a table. >lua
|
|
||||||
-- Equivalent to:
|
|
||||||
vim.iter(f):totable()
|
|
||||||
<
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
• {f} (`function`) Iterator function
|
|
||||||
|
|
||||||
Return: ~
|
|
||||||
(`table`)
|
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Lua module: vim.snippet *vim.snippet*
|
Lua module: vim.snippet *vim.snippet*
|
||||||
|
@ -153,6 +153,8 @@ unreleased features on Nvim HEAD.
|
|||||||
|
|
||||||
• Changed the signature of `vim.diagnostic.enable()`.
|
• Changed the signature of `vim.diagnostic.enable()`.
|
||||||
|
|
||||||
|
• Removed vim.iter.map(), vim.iter.filter(), vim.iter.totable().
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
NEW FEATURES *news-features*
|
NEW FEATURES *news-features*
|
||||||
|
|
||||||
|
@ -60,9 +60,6 @@
|
|||||||
--- vim.iter(rb):totable()
|
--- vim.iter(rb):totable()
|
||||||
--- -- { "a", "b" }
|
--- -- { "a", "b" }
|
||||||
--- ```
|
--- ```
|
||||||
---
|
|
||||||
--- In addition to the |vim.iter()| function, the |vim.iter| module provides
|
|
||||||
--- convenience functions like |vim.iter.filter()| and |vim.iter.totable()|.
|
|
||||||
|
|
||||||
--- LuaLS is bad at generics which this module mostly deals with
|
--- LuaLS is bad at generics which this module mostly deals with
|
||||||
--- @diagnostic disable:no-unknown
|
--- @diagnostic disable:no-unknown
|
||||||
@ -1092,55 +1089,6 @@ function ListIter.new(t)
|
|||||||
return it
|
return it
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Collects an |iterable| into a table.
|
|
||||||
---
|
|
||||||
--- ```lua
|
|
||||||
--- -- Equivalent to:
|
|
||||||
--- vim.iter(f):totable()
|
|
||||||
--- ```
|
|
||||||
---
|
|
||||||
---@param f function Iterator function
|
|
||||||
---@return table
|
|
||||||
function M.totable(f, ...)
|
|
||||||
return Iter.new(f, ...):totable()
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Filters a table or other |iterable|.
|
|
||||||
---
|
|
||||||
--- ```lua
|
|
||||||
--- -- Equivalent to:
|
|
||||||
--- vim.iter(src):filter(f):totable()
|
|
||||||
--- ```
|
|
||||||
---
|
|
||||||
---@see |Iter:filter()|
|
|
||||||
---
|
|
||||||
---@param f fun(...):boolean Filter function. Accepts the current iterator or table values as
|
|
||||||
--- arguments and returns true if those values should be kept in the
|
|
||||||
--- final table
|
|
||||||
---@param src table|function Table or iterator function to filter
|
|
||||||
---@return table
|
|
||||||
function M.filter(f, src, ...)
|
|
||||||
return Iter.new(src, ...):filter(f):totable()
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Maps a table or other |iterable|.
|
|
||||||
---
|
|
||||||
--- ```lua
|
|
||||||
--- -- Equivalent to:
|
|
||||||
--- vim.iter(src):map(f):totable()
|
|
||||||
--- ```
|
|
||||||
---
|
|
||||||
---@see |Iter:map()|
|
|
||||||
---
|
|
||||||
---@param f fun(...): any? Map function. Accepts the current iterator or table values as
|
|
||||||
--- arguments and returns one or more new values. Nil values are removed
|
|
||||||
--- from the final table.
|
|
||||||
---@param src table|function Table or iterator function to filter
|
|
||||||
---@return table
|
|
||||||
function M.map(f, src, ...)
|
|
||||||
return Iter.new(src, ...):map(f):totable()
|
|
||||||
end
|
|
||||||
|
|
||||||
return setmetatable(M, {
|
return setmetatable(M, {
|
||||||
__call = function(_, ...)
|
__call = function(_, ...)
|
||||||
return Iter.new(...)
|
return Iter.new(...)
|
||||||
|
Loading…
Reference in New Issue
Block a user