Effect.ts: Absence as First-Class

Core ConceptsLesson 1 of 51

1. The Core Idea: Absence as First-Class

Traditional code assumes values exist. Effect code describes HOW to get values that don't exist yet.

Code Example
// Traditional: assumes 'user' exists
function getUserName(userId) {
  const user = database.get(userId);
  return user.name;  // What if database fails?
}

// Effect: describes HOW to get user
Effect<User, DatabaseError, Database>
//     ^^^^  ^^^^^^^^^^^^^  ^^^^^^^^
//     What  How it fails   What it needs
Explanation

The key insight: Effect represents unavailability as a first-class concept.

Traditional code makes assumptions:

  • The database is available
  • The query will work
  • We'll get a result

Effect makes NO assumptions. Instead, it TYPES the unavailability:

  • User might not be available (we describe HOW to get it)
  • DatabaseError describes HOW it can be unavailable (failure)
  • Database service might not be available (we require it)

We're not executing anything. We're building a TYPE-SAFE description of data that doesn't exist yet.


Part 1 of 51 in the Effect.ts Absence Modeling series