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

Feature - Value in List/Hash #374

Open
fuseraft opened this issue Nov 10, 2024 · 0 comments
Open

Feature - Value in List/Hash #374

fuseraft opened this issue Nov 10, 2024 · 0 comments
Labels

Comments

@fuseraft
Copy link
Owner

Currently, to quickly check if a list contains a value, we use the .contains() builtin.

Example of using .contains()

list  = [1, 2, 3]
value = 2

if list.contains(value)
  println "${list} contains ${value}"
end

To check if a hash contains a key, we use the .has_key() builtin. Alternatively, we can use the .keys() builtin, and call .contains() on that.

Example of using .has_key()

hash = { "name": "Scott", "website": "https://fuseraft.com" }
key = "name"

# check if hash contains a given key
if hash.has_key(key)
  println "${hash} contains ${key}"
end

# it is functionally equivalent to:
if hash.keys().contains(key)
  println "${hash} contains ${key}"
end

Perhaps we can introduce a new usage for the in keyword that consolidates these.

Example of proposed in keyword usage

list  = [1, 2, 3]
value = 2

if value in list
  println "${list} contains ${value}"
end

hash = { "name": "Scott", "website": "https://fuseraft.com" }
key = "name"

if key in hash.keys()
  println "${hash} contains ${key}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant