Effect.ts: Absence as First-Class

Core ConceptsLesson 2 of 51

2. Success Effect

An effect that always succeeds - the data 'exists' immediately

Code Example
const greet = Effect.succeed("Hello!");

// Type signature tells the whole story:
// Effect<string, never, never>
//        ^^^^^^  ^^^^^  ^^^^^
//        Returns string
//                Never fails
//                       Needs nothing

const result = await Effect.runPromise(greet);
// result = "Hello!"
Explanation

Even success is typed unavailability!

We're not saying "here's a string". We're saying:

  • This string is UNAVAILABLE until you run the effect
  • But when you run it, it WILL be available (never fails)
  • And it needs NOTHING to become available

Effect.succeed doesn't give you the value - it gives you a DESCRIPTION of how to get a value that's guaranteed to be available. No assumptions about when or where it runs.


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