Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 799 Bytes

File metadata and controls

58 lines (43 loc) · 799 Bytes

Maps in TechScript

Maps (also known as dictionaries or hash maps) are collections of key-value pairs.


🏗️ Initialization

Declare maps using curly braces:

user = {
    "name": "Alice",
    "age": 30,
    "is_active": true
}

🧬 Elements Access & Modifications

Retrieval & Assignment

Access values using keys:

say user["name"] # "Alice"

user["age"] = 31 # Update value
user["role"] = "admin" # Insert new key

🔁 Iteration

Iterate over all keys:

for key in user
    say $"{key} is {user[key]}"
end

📏 Properties

Length

Retrieve the number of key-value pairs in a map:

say len(user) # 4

Containment

Check if a key exists in a map:

when "role" in user
    say "Role is defined!"
end