Effect.ts: Absence as First-Class

Core ConceptsLesson 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:

  1. Get the user ID (assumes it's available)
  2. Transform it (assumes step 1 worked)
  3. Hope nothing breaks

Effect approach:

  1. Describe transformation of UNAVAILABLE data
  2. Build up the description (nothing executes)
  3. 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