Files

Task Manager Showcase

This example demonstrates Lux's three killer features in a practical, real-world context.

Running the Example

lux run examples/showcase/task_manager.lux

Features Demonstrated

1. Algebraic Effects

Every function signature shows exactly what side effects it can perform:

fn createTask(title: String, priority: String): Task@latest
    with {TaskStore, Random} = { ... }
  • TaskStore - database operations
  • Random - random number generation
  • No hidden I/O or surprise calls

2. Behavioral Types

Compile-time guarantees about function behavior:

fn formatTask(task: Task@latest): String
    is pure           // No side effects
    is deterministic  // Same input = same output
    is total          // Always terminates
fn completeTask(id: String): Option<Task@latest>
    is idempotent     // Safe to retry
    with {TaskStore}

3. Schema Evolution

Versioned types with automatic migration:

type Task @v2 {
    id: String,
    title: String,
    done: Bool,
    priority: String,  // New in v2

    from @v1 = { ...old, priority: "medium" }
}

4. Handler Swapping (Testing)

Test without mocks by swapping effect handlers:

// Production
run processOrders() with {
    TaskStore = PostgresTaskStore,
    Logger = CloudLogger
}

// Testing
run processOrders() with {
    TaskStore = InMemoryTaskStore,
    Logger = SilentLogger
}

Why This Matters

Traditional Languages Lux
Side effects are implicit Effects in type signatures
Runtime crashes Compile-time verification
Complex mocking frameworks Simple handler swapping
Manual migration code Automatic schema evolution
Hope for retry safety Verified idempotency

File Structure

showcase/
├── README.md           # This file
└── task_manager.lux    # Main example with all features

Key Sections in the Code

  1. Versioned Data Types - Task @v1, @v2, @v3 with migrations
  2. Pure Functions - is pure, is total, is deterministic, is idempotent
  3. Effects - effect TaskStore and effect Logger
  4. Effect Handlers - InMemoryTaskStore, ConsoleLogger
  5. Testing - runTestScenario() with swapped handlers
  6. Migration Demo - demonstrateMigration()

Next Steps