Originally Posted by Sasky
The IF would return true as long as v isn't NIL or boolean false. If it's NIL, it shouldn't even be iterated over. If it's a function it can't be false.
|
Yeah I just wasn't sure if v was actually functions like I thought or if it could ever possibly be something else.
Originally Posted by Sasky
As far as the short circuit, it could be simplified even more if v(slot) always returns a boolean:
Lua Code:
function(slot) for _,v in pairs(filters[filterType]) do if not v(slot) then return false end end return true end
If you hit false, it'll carry the false throughout, and the rest of the filters aren't necessary (as merlight noted) so you can immediately exit. Similarly, this also means a true return will only happen if and only if it iterates through the whole loop. And every time it processes the whole loop it'll return true, so the running assignment is unnecessary. Not as much of an optimization as early exit, but does save some assignment operations.
|
Oh, nice one.