Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add util.In( any thing, vararg values ) #2056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Feb 21, 2024

  1. Add util.In( any thing, vararg values )

    Allows you to check if `thing` is among `values`.
    Using the function, we can do this:
    
    ```lua
    local myUsergroup = 'user'
    if util.In( curState, 'user', 'vip' ) then
        -- ...
    end
    ```
    
    ... instead of:
    ```lua
    local allowedUsergroups = {
        user = true,
        vip = true,
    }
    
    local myUsergroup = 'user'
    if allowedUsergroups[ myUsergroup ] then
        -- ...
    end
    ```
    
    Of course, the second code is faster because it performs a key lookup (which is O(1) vs. my O(n) implementation), but `util.In` is useful in contexts where performance is not so important
    bydlocodd authored Feb 21, 2024
    Configuration menu
    Copy the full SHA
    413edb6 View commit details
    Browse the repository at this point in the history