From 559c4339a47364e2a57e637f1104d656e7461df1 Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Wed, 2 Aug 2023 13:01:57 -0500 Subject: [PATCH] Fix aura list finding --- src/AuraTable/AuraTable.lua | 40 ++++++++++++++++++++++++++----------- src/List/List.lua | 6 +++++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 981b564..2eceb38 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -388,27 +388,39 @@ end ---@param spells List ---@return Aura function AuraTable:FindAnyOf(spells) - return spells:find(function(spell) - return self:FindAny(spell):IsValid() - end) or Bastion.Aura:New() + return spells:reduce(function(acc, cur) + local aura = self:FindAny(cur) + if aura:IsValid() then + return aura, true + end + return acc + end, Bastion.Aura:New()) end -- FindAnyOfMy ---@param spells List ---@return Aura function AuraTable:FindAnyOfMy(spells) - return spells:find(function(spell) - return self:FindMy(spell):IsValid() - end) or Bastion.Aura:New() + return spells:reduce(function(acc, cur) + local aura = self:FindMy(cur) + if aura:IsValid() then + return aura, true + end + return acc + end, Bastion.Aura:New()) end -- FindAnyOfTheirs ---@param spells List ---@return Aura function AuraTable:FindAnyOfTheirs(spells) - return spells:find(function(spell) - return self:FindTheirs(spell):IsValid() - end) or Bastion.Aura:New() + return spells:reduce(function(acc, cur) + local aura = self:FindTheirs(cur) + if aura:IsValid() then + return aura, true + end + return acc + end, Bastion.Aura:New()) end -- FindAnyFrom @@ -416,9 +428,13 @@ end ---@param source Unit ---@return Aura function AuraTable:FindAnyFrom(spells, source) - return spells:find(function(spell) - return self:FindFrom(spell, source):IsValid() - end) or Bastion.Aura:New() + return spells:reduce(function(acc, cur) + local aura = self:FindFrom(cur, source) + if aura:IsValid() then + return aura, true + end + return acc + end, Bastion.Aura:New()) end -- Has any stealable aura diff --git a/src/List/List.lua b/src/List/List.lua index 1921466..28ef98e 100644 --- a/src/List/List.lua +++ b/src/List/List.lua @@ -114,8 +114,12 @@ end ---@return boolean function List:reduce(callback, initialValue) local result = initialValue + local done = false for _, v in ipairs(self._list) do - result = callback(result, v) + result, done = callback(result, v) + if done then + break + end end return result end