Merge branch 'rxi:master' into master

This commit is contained in:
Rose Liverman
2025-07-20 17:53:40 -06:00
committed by GitHub
3 changed files with 7 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
Copyright (c) 2018 rxi Copyright (c) 2020 rxi
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of

View File

@@ -1,7 +1,7 @@
-- --
-- lume -- lume
-- --
-- Copyright (c) 2018 rxi -- Copyright (c) 2020 rxi
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a copy of -- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in -- this software and associated documentation files (the "Software"), to deal in
@@ -165,7 +165,7 @@ end
function lume.isarray(x) function lume.isarray(x)
return (type(x) == "table" and x[1] ~= nil) and true or false return type(x) == "table" and x[1] ~= nil
end end
@@ -293,8 +293,8 @@ end
function lume.reduce(t, fn, first) function lume.reduce(t, fn, first)
local started = first ~= nil
local acc = first local acc = first
local started = first and true or false
local iter = getiter(t) local iter = getiter(t)
for _, v in iter(t) do for _, v in iter(t) do
if started then if started then

View File

@@ -141,7 +141,6 @@ tests["lume.remove"] = function()
testeq(t, { 2, 4, 5 }) testeq(t, { 2, 4, 5 })
lume.remove(t, 5) lume.remove(t, 5)
testeq(t, { 2, 4 }) testeq(t, { 2, 4 })
local m = { a = 1, b = 2, c = 3 }
local x = lume.remove(t, 123) local x = lume.remove(t, 123)
testeq(x, 123) testeq(x, 123)
end end
@@ -245,6 +244,7 @@ end
tests["lume.reduce"] = function() tests["lume.reduce"] = function()
local concat = function(a, b) return a .. b end local concat = function(a, b) return a .. b end
local add = function(a, b) return a + b end local add = function(a, b) return a + b end
local any = function(a, b) return a or b end
testeq( lume.reduce({"cat", "dog"}, concat, ""), "catdog" ) testeq( lume.reduce({"cat", "dog"}, concat, ""), "catdog" )
testeq( lume.reduce({"cat", "dog"}, concat, "pig"), "pigcatdog" ) testeq( lume.reduce({"cat", "dog"}, concat, "pig"), "pigcatdog" )
testeq( lume.reduce({"me", "ow"}, concat), "meow" ) testeq( lume.reduce({"me", "ow"}, concat), "meow" )
@@ -254,6 +254,8 @@ tests["lume.reduce"] = function()
testeq( lume.reduce({}, concat, "potato"), "potato" ) testeq( lume.reduce({}, concat, "potato"), "potato" )
testeq( lume.reduce({a=1, b=2}, add, 5), 8 ) testeq( lume.reduce({a=1, b=2}, add, 5), 8 )
testeq( lume.reduce({a=1, b=2}, add), 3 ) testeq( lume.reduce({a=1, b=2}, add), 3 )
testeq( lume.reduce({false, false, false}, any), false )
testeq( lume.reduce({false, true, false}, any), true )
tester.test.error(lume.reduce, {}, add) tester.test.error(lume.reduce, {}, add)
end end