Effect.ts: Absence as First-Class
Core Concepts • Lesson 4 of 51
4. The Magic: Composing Absence
Chain operations on values that don't exist yet
Code Example
// Start with absence
const getUserId = Effect.succeed(123);
// Transform it (still absent!)
const getUserName = getUserId.pipe(
Effect.map(id => `user_${id}`)
);
// Still haven't resolved absence!
// We've just described the transformation.
// NOW we resolve it:
const name = await Effect.runPromise(getUserName);
// name = "user_123"
Explanation
Composing unavailability without assumptions!
Key insight: We're transforming data that DOESN'T EXIST YET.
Traditional approach:
- Get the user ID (assumes it's available)
- Transform it (assumes step 1 worked)
- Hope nothing breaks
Effect approach:
- Describe transformation of UNAVAILABLE data
- Build up the description (nothing executes)
- Only when we run it do we resolve unavailability
We never assumed the data exists. We described how to transform it IF it becomes available.
Part 4 of 51 in the Effect.ts Absence Modeling series