Skip to content

Commit

Permalink
Merge pull request #10 from svermeulen/sverm/unique_by_fix
Browse files Browse the repository at this point in the history
Bug fix to uniqueBy to avoid passing nil values to given selector
  • Loading branch information
Henkoglobin authored Feb 25, 2024
2 parents 193211f + 9164124 commit bbbe323
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lazylualinq/linq.lua
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,16 @@ function linq:uniqueBy(selector)

return function()
local value, index, key
repeat
while true do
value, index = it()
if index == nil then
break
end
key = selector(value)
until index == nil or not seen[key]
if not seen[key] then
break
end
end

if key ~= nil then
seen[key] = true
Expand Down

0 comments on commit bbbe323

Please sign in to comment.