292292-- license for previous Vim releases instead of the license that they came
293293-- with, at your option.
294294
295-
296295--- @defgroup vim.iter
297296---
298297--- This module provides a generic interface for working with
@@ -381,22 +380,22 @@ end
381380local packedmt = {}
382381
383382local function unpack (t )
384- if type (t ) == ' table' and getmetatable (t ) == packedmt then
383+ if type (t ) == " table" and getmetatable (t ) == packedmt then
385384 return _G .unpack (t , 1 , t .n )
386385 end
387386 return t
388387end
389388
390389local function pack (...)
391- local n = select (' # ' , ... )
390+ local n = select (" # " , ... )
392391 if n > 1 then
393392 return setmetatable ({ n = n , ... }, packedmt )
394393 end
395394 return ...
396395end
397396
398397local function sanitize (t )
399- if type (t ) == ' table' and getmetatable (t ) == packedmt then
398+ if type (t ) == " table" and getmetatable (t ) == packedmt then
400399 -- Remove length tag
401400 t .n = nil
402401 end
413412--- @return boolean True if the iterator stage should continue , false otherwise
414413--- @return any Function arguments.
415414local function continue (...)
416- if select (' # ' , ... ) > 0 then
415+ if select (" # " , ... ) > 0 then
417416 return false , ...
418417 end
419418 return true
429428--- @return boolean True if the iterator pipeline should continue , false otherwise
430429--- @return any Return values of f
431430local function apply (f , ...)
432- if select (' # ' , ... ) > 0 then
431+ if select (" # " , ... ) > 0 then
433432 return continue (f (... ))
434433 end
435434 return false
560559--- in the pipeline as arguments.
561560function Iter .each (self , f )
562561 local function fn (...)
563- if select (' # ' , ... ) > 0 then
562+ if select (" # " , ... ) > 0 then
564563 f (... )
565564 return true
566565 end
739738---
740739--- @return Iter
741740function Iter .rev (self )
742- error (' rev() requires a list-like table' )
741+ error (" rev() requires a list-like table" )
743742 return self
744743end
745744
769768---
770769--- @return any
771770function Iter .peek (self ) -- luacheck: no unused args
772- error (' peek() requires a list-like table' )
771+ error (" peek() requires a list-like table" )
773772end
774773
775774--- @private
802801---
803802--- @return any
804803function Iter .find (self , f )
805- if type (f ) ~= ' function' then
804+ if type (f ) ~= " function" then
806805 local val = f
807806 f = function (v )
808807 return v == val
@@ -848,12 +847,12 @@ end
848847---
849848--- @return any
850849function Iter .rfind (self , f ) -- luacheck: no unused args
851- error (' rfind() requires a list-like table' )
850+ error (" rfind() requires a list-like table" )
852851end
853852
854853--- @private
855854function ListIter .rfind (self , f ) -- luacheck: no unused args
856- if type (f ) ~= ' function' then
855+ if type (f ) ~= " function" then
857856 local val = f
858857 f = function (v )
859858 return v == val
886885---
887886--- @return any
888887function Iter .nextback (self ) -- luacheck: no unused args
889- error (' nextback() requires a list-like table' )
888+ error (" nextback() requires a list-like table" )
890889end
891890
892891function ListIter .nextback (self )
914913---
915914--- @return any
916915function Iter .peekback (self ) -- luacheck: no unused args
917- error (' peekback() requires a list-like table' )
916+ error (" peekback() requires a list-like table" )
918917end
919918
920919function ListIter .peekback (self )
970969--- @param n number Number of values to skip.
971970--- @return Iter
972971function Iter .skipback (self , n ) -- luacheck: no unused args
973- error (' skipback() requires a list-like table' )
972+ error (" skipback() requires a list-like table" )
974973 return self
975974end
976975
@@ -1181,9 +1180,9 @@ end
11811180--- @private
11821181function Iter .new (src , ...)
11831182 local it = {}
1184- if type (src ) == ' table' then
1183+ if type (src ) == " table" then
11851184 local mt = getmetatable (src )
1186- if mt and type (mt .__call ) == ' function' then
1185+ if mt and type (mt .__call ) == " function" then
11871186 --- @private
11881187 function it .next ()
11891188 return src ()
@@ -1209,7 +1208,7 @@ function Iter.new(src, ...)
12091208 return ListIter .new (t )
12101209 end
12111210
1212- if type (src ) == ' function' then
1211+ if type (src ) == " function" then
12131212 local s , var = ...
12141213
12151214 --- Use a closure to handle var args returned from iterator
@@ -1227,7 +1226,7 @@ function Iter.new(src, ...)
12271226
12281227 setmetatable (it , Iter )
12291228 else
1230- error (' src must be a table or function' )
1229+ error (" src must be a table or function" )
12311230 end
12321231 return it
12331232end
@@ -1301,4 +1300,3 @@ return setmetatable(M, {
13011300 return Iter .new (... )
13021301 end ,
13031302})
1304-
0 commit comments