cxmeel / sift

Immutable data library for Luau.
https://csqrl.github.io/sift/
MIT License
62 stars 10 forks source link

Allow reduce and reduceRight to work on falsy values #15

Closed davidnurkkala closed 1 year ago

davidnurkkala commented 1 year ago

Had a problem where I was trying to detect state change by using an array of results returned by setter functions. Essentially,

if Sift.Array.reduce(results :: {boolean}, function(accumulator, changed)
  return accumulator or changed
end, false) then
  -- something changed
end

Found out that it assumed the initial value to not be a truthy value. Changed it to compare directly to nil instead.

cxmeel commented 1 year ago

Merged into main