Lua-Modules icon indicating copy to clipboard operation
Lua-Modules copied to clipboard

docs(standard): add `nodiscard` to immutable array functions

Open Rathoz opened this issue 2 years ago • 4 comments

Summary

Some functions are expecting the return value to be used, as they should have no side effects themselves as being immuntable. Add nodiscard to these functions allows to faster spot potential bugs in the code (such as was seen with #4183)

How did you test this change?

tested by hjp

Rathoz avatar Apr 16 '24 10:04 Rathoz

Done the fixes, but not tested, would be great is someone could

Rathoz avatar Apr 16 '24 11:04 Rathoz

tested (via previews) on dota, lol, brawlstars, valorant, wildrift, overwatch and stormgate

hjpalpha avatar Apr 16 '24 12:04 hjpalpha

Given most of the changes happen to Array.mapIndexes, would it make sense to add a second version of that, e.g. forEachIndexed or something, which would not return anything? Iterating a second time shouldn't really be necessary, no? Otherwise, does local _ = Array.mapIndexes also silence the errors?

I agree that some new function would be better, and have it stop when an iteration returns false/nil (or continue until they stop returning a true?). Not sure what a good name would be though. forEachIndexed. Maybe just call it for and have optional(?) params which are starting and ending indexed that default to 1 and math.huge? So it would just be a for index = startIndex, endIndex do loop but in a function. Or we could just use for index = 1, math.huge do instead :p

iMarbot avatar May 01 '24 11:05 iMarbot

I agree that some new function would be better, and have it stop when an iteration returns false/nil (or continue until they stop returning a true?). Not sure what a good name would be though. forEachIndexed. Maybe just call it for and have optional(?) params which are starting and ending indexed that default to 1 and math.huge? So it would just be a for index = startIndex, endIndex do loop but in a function. Or we could just use for index = 1, math.huge do instead :p

Blame me for not looking up what the function actually does. Nontheless, it looks like all the usages shown in this PR aren't the intended use case

mbergen avatar May 01 '24 13:05 mbergen