Effect · reference

Reference

The Effect type

A lazy, immutable description. Nothing runs until a run* function interprets it.

Effect<Success, Error, Requirements>

A · Success

Value produced on success. void = no payload. never = never succeeds (runs forever, or only fails).

E · Error

Expected, recoverable failures. never = cannot fail that way (no values of never).

R · Requirements

Services the runtime must provide. never = empty context; you can run it now.

Abbreviations in the ecosystem: A / E / R. Defaults in TypeScript: omitted E and R are never, so Effect.succeed(42) is Effect<number, never, never>.

What it is not

Construct vs run

import { Effect } from "effect"

const program = Effect.sync(() => {
  console.log("Hello, World!")
  return 1
})
// still silent

const result = Effect.runSync(program)
// logs, then result === 1

Keep run* at the edge of the program. Default to runPromise or runFork. runSync is for effects you know are synchronous and non-failing; async work inside it throws AsyncFiberException.

API Gives
runSyncA (or throws)
runSyncExitExit<A, E>
runPromisePromise<A>
runPromiseExitPromise<Exit<A, E>>
runForkRuntimeFiber<A, E>

React boundary (install docs)

Hold the description; run on the event.

const task = useMemo(
  () => Effect.sync(() => setCount((n) => n + 1)),
  [setCount]
)
const increment = useCallback(() => Effect.runSync(task), [task])

Effect does not replace useState. It describes the work the click performs.