radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 2 forks source link

[Feature]: Membership operator support. (REP-8) #110

Closed Almas-Ali closed 2 months ago

Almas-Ali commented 2 months ago

Describe the solution you'd like When we use data in datatype it should return Boolean value as output.

Describe alternatives you've considered Example

# with Array
arr = [1,2,3,4,5]

# with if-else
if 1 in arr {
    print("Data found.")
}
else {
    print("Not found.")
}

# Normal testing
print(2 in arr)

# with while loop
while 3 in arr {
    # do something
}

# this should also work for HashMap as well.

Some test cases:

arr = [1,2,3,4,5]
assert 4 in arr

hash = {
    "key1": "value1",
    "key2": "value2"
}
assert "key2" in hash # This will search in HashMap->Keys

Additional context Membership operators are very useful in Python world to check if any value exists in a datatype (Array, HashMap).