From 9e0f56e3e901ba83e90764d6d56f1b086c3f703a Mon Sep 17 00:00:00 2001 From: Jay Thomas Date: Fri, 8 Mar 2019 09:58:40 -0500 Subject: [PATCH 1/3] Remove unnecessary expression; Add test First half of the expression returns a boolean already so the second half is redundant --- lume.lua | 2 +- test/test.lua | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lume.lua b/lume.lua index 1c1b742..83650e0 100644 --- a/lume.lua +++ b/lume.lua @@ -158,7 +158,7 @@ end 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 diff --git a/test/test.lua b/test/test.lua index 25ce17e..bfc1572 100644 --- a/test/test.lua +++ b/test/test.lua @@ -141,7 +141,6 @@ tests["lume.remove"] = function() testeq(t, { 2, 4, 5 }) lume.remove(t, 5) testeq(t, { 2, 4 }) - local m = { a = 1, b = 2, c = 3 } local x = lume.remove(t, 123) testeq(x, 123) end @@ -245,6 +244,7 @@ end tests["lume.reduce"] = function() local concat = 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, "pig"), "pigcatdog" ) testeq( lume.reduce({"me", "ow"}, concat), "meow" ) @@ -254,6 +254,8 @@ tests["lume.reduce"] = function() testeq( lume.reduce({}, concat, "potato"), "potato" ) testeq( lume.reduce({a=1, b=2}, add, 5), 8 ) 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) end From 6389f859c65a0d0ec966d5ebac41f5f52fbb3345 Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 12 Feb 2020 21:09:33 +0000 Subject: [PATCH 2/3] Made lume.reduce check initial value for `nil` instead of `non-truthy` Fixes #32 --- lume.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lume.lua b/lume.lua index 83650e0..0ffc738 100644 --- a/lume.lua +++ b/lume.lua @@ -286,8 +286,8 @@ end function lume.reduce(t, fn, first) + local started = first ~= nil local acc = first - local started = first and true or false local iter = getiter(t) for _, v in iter(t) do if started then @@ -724,7 +724,7 @@ end local ripairs_iter = function(t, i) i = i - 1 local v = t[i] - if v ~= nil then + if v ~= nil then return i, v end end From 98847e7812cf28d3d64b289b03fad71dc704547d Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 12 Feb 2020 21:11:26 +0000 Subject: [PATCH 3/3] Updated copyright year; 2018 => 2020 --- LICENSE | 2 +- lume.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 8ce02b9..9eb37b1 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/lume.lua b/lume.lua index 0ffc738..2157891 100644 --- a/lume.lua +++ b/lume.lua @@ -1,7 +1,7 @@ -- -- lume -- --- Copyright (c) 2018 rxi +-- Copyright (c) 2020 rxi -- -- 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