Skip to content

Commit efb3509

Browse files
committed
feat(List): add isempty method
1 parent 62dae8a commit efb3509

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

spec/List_spec.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ describe("mods.List", function()
9090
{ "insert" , abc__ , { "d" } , abcd_ , true },
9191
{ "intersection" , a_c_e , { _bcd_ } , __c__ , false },
9292
{ "invert" , a___e , { } , a1_e2 , false },
93+
{ "isempty" , _____ , { } , true , },
94+
{ "isempty" , abc__ , { } , false , },
9395
{ "join" , abc__ , { "," } , "a,b,c" , },
9496
{ "join" , abcde , { } , "abcde" , },
9597
{ "keypath" , abc__ , { } , "a.b.c" , },
@@ -126,7 +128,6 @@ describe("mods.List", function()
126128
{ "tostring" , a___e , { } , '{ "a", "e" }' , },
127129
{ "uniq" , AZAZA , { } , AZ___ , false },
128130
{ "zip" , abc__ , { _12__ } , { a1, b2 } , false },
129-
{ "join" , ____e , { } , 'e' , },
130131

131132
-- Cases where the second argument is provided as a Set.
132133
{ "difference" , a_c_e , { Set(_bcd_) } , a___e , false },

src/mods/List.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ function List:len()
294294
return #self
295295
end
296296

297+
function List:isempty()
298+
return #self == 0
299+
end
300+
297301
function List:lt(ls)
298302
return lex_cmp(self, ls) == -1
299303
end

types/List.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,18 @@ function List:index_if(pred) end
406406
---@nodiscard
407407
function List:len() end
408408

409+
---
410+
---Return whether the list has no elements.
411+
---
412+
---```lua
413+
---ok = List():isempty() --> true
414+
---```
415+
---
416+
---@param self mods.List|any[] Current list.
417+
---@return boolean empty `true` when the list has no elements.
418+
---@nodiscard
419+
function List:isempty() end
420+
409421
--------------------------------------------------------------------------------
410422
------------------------------------ Access ------------------------------------
411423
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)