📌 Enumy

Enumy definiują zbiór nazwanych stałych.

Podstawowy enum

enum Color { RED, GREEN, BLUE } print(Color.RED); // 0 print(Color.GREEN); // 1 print(Color.BLUE); // 2

Enum z wartościami

enum Status { PENDING = 1, ACTIVE = 2, DONE = 3 } print(Status.PENDING); // 1 print(Status.ACTIVE); // 2

Użycie w warunkach

enum Priority { LOW, MEDIUM, HIGH } fn processTask(task) { if (task.priority == Priority.HIGH) { print("Processing HIGH priority!"); } } let task = {name: "Important", priority: Priority.HIGH}; processTask(task);

Enum w when/switch

enum Direction { UP, DOWN, LEFT, RIGHT } fn move(dir) { let result = when dir { Direction.UP -> "Moving up", Direction.DOWN -> "Moving down", Direction.LEFT -> "Moving left", Direction.RIGHT -> "Moving right", _ -> "Unknown direction" }; return result; } print(move(Direction.UP)); // "Moving up"