← Về danh sách bài học Bài 2/20

💧 Bài 2: Kiểu dữ liệu cơ bản

⏱️ Thời gian đọc: 20 phút | 📚 Khóa học Elixir

🎯 Sau bài học này, bạn sẽ:

1. Atoms

Atoms là constants có tên chính là giá trị của nó.

:ok
:error
:hello_world

# Atoms thường dùng cho status
{:ok, result}
{:error, reason}

2. Tuples

# Tuple - ordered, fixed size
{:ok, "Hello", 42}
tuple = {1, 2, 3}
elem(tuple, 0)  # 1

3. Lists

# List - linked list
[1, 2, 3, 4, 5]
["a", "b", "c"]

# Head and Tail
[head | tail] = [1, 2, 3]
# head = 1, tail = [2, 3]

4. Maps

# Maps - key-value pairs
user = %{name: "John", age: 30}
user.name     # "John"
user[:age]    # 30

# Update map (creates new map)
updated = %{user | age: 31}

📝 Tóm Tắt