Effect.ts: Absence as First-Class
Core Concepts • Lesson 3 of 51
3. Failure Effect
An effect that always fails - modeling absence through explicit failure
Code Example
const fail = Effect.fail("Not found!");
// Effect<never, string, never>
// ^^^^^ ^^^^^^
// Never succeeds
// Fails with string
try {
await Effect.runPromise(fail);
} catch (error) {
console.log(error); // "Not found!"
}
Explanation
Failure = Typed unavailability through explicit absence.
Traditional code assumes values exist, then crashes when they don't. Effect TYPES the unavailability:
Effect<never, string, never>says "this will NEVER be available"- The error type (string) describes WHY it's unavailable
- No assumptions: we explicitly model "this data doesn't exist"
This is the core philosophy: don't assume data exists. Type its absence.
Part 3 of 51 in the Effect.ts Absence Modeling series