effect-core
This skill should be used ANY TIME you're writing TypeScript with Effect, especially when the user asks about "Effect type", "creating effects", "running effects", "Effect.gen", "Effect.succeed", "Effect.fail", "Effect.sync", "Effect.promise", "Effect.tryPromise", "Effect.runPromise", "Effect.runSync", "pipe", "andThen", "flatMap", "map", "Effect basics", or needs to understand the fundamental Effect<Success, Error, Requirements> type and how to create, compose, and run effects.
What this skill does
# Effect Core
## CRITICAL: You MUST Follow the Code Style Skill
**Before writing ANY Effect code, you MUST read and follow the [Code Style](../code-style/SKILL.md) skill ([view on GitHub](https://github.com/andrueandersoncs/claude-skill-effect-ts/blob/main/skills/code-style/SKILL.md)).** This skill covers core APIs and composition only — the Code Style skill defines the mandatory patterns, forbidden anti-patterns, and idiomatic conventions that apply to ALL Effect code you produce. Every code example you generate must conform to those rules.
## Overview
Effect is the foundational type in Effect-TS representing a computation that may succeed with value `A`, fail with error `E`, or require context `R`:
```typescript
Effect<Success, Error, Requirements>;
// Also written as: Effect<A, E, R>
```
The key insight: Effects are **descriptions** of programs, not executed code. They must be explicitly run.
## Creating Effects
### From Synchronous Values
```typescript
import { Effect } from "effect";
const success = Effect.succeed(42);
const failure = Effect.fail(new Error("Something went wrong"));
const lazy = Effect.sync(() => {
console.log("Computing...");
return Math.random();
});
// Sync that may throw (converts exception to typed error)
const mayThrow = Effect.try({
try: () => someLegacyFunction(),
catch: (error) => new LegacyError({ cause: error }),
});
// For JSON parsing, prefer Schema.parseJson (type-safe and validated)
const UserInput = Schema.parseJson(
Schema.Struct({
name: Schema.String,
value: Schema.Number,
}),
);
const parsed = Schema.decodeUnknown(UserInput)(userInput);
```
### From Asynchronous Values
```typescript
// From Promise (untyped error)
const fromPromise = Effect.promise(() => fetch("/api/data"));
// From Promise with typed error
const fromPromiseTyped = Effect.tryPromise({
try: () => fetch("/api/data"),
catch: (error) => new FetchError({ cause: error }),
});
```
## Composing Effects
### Sequential Composition with pipe
```typescript
import { Effect, pipe } from "effect";
const program = pipe(
Effect.succeed(1),
Effect.map((n) => n + 1),
Effect.flatMap((n) => Effect.succeed(n * 2)),
Effect.andThen((n) => Effect.succeed(`Result: ${n}`)),
);
```
### Generator Syntax (Recommended)
The generator syntax (`Effect.gen`) provides cleaner, more readable code:
```typescript
const program = Effect.gen(function* () {
const a = yield* Effect.succeed(1);
const b = yield* Effect.succeed(2);
const result = a + b;
return `Sum: ${result}`;
});
```
Equivalent to:
```typescript
const program = Effect.succeed(1).pipe(
Effect.flatMap((a) => Effect.succeed(2).pipe(Effect.flatMap((b) => Effect.succeed(`Sum: ${a + b}`)))),
);
```
## Running Effects
Effects are descriptions that must be run to produce values:
```typescript
import { Effect } from "effect";
const program = Effect.succeed(42);
const result = await Effect.runPromise(program);
const syncResult = Effect.runSync(Effect.succeed(42));
const exit = await Effect.runPromiseExit(program);
```
### Runtime Methods
| Method | Use Case |
| ----------------------- | --------------------------------------------- |
| `Effect.runPromise` | Async effect → Promise (throws on failure) |
| `Effect.runPromiseExit` | Async effect → Promise<Exit> (never throws) |
| `Effect.runSync` | Sync effect → value (throws on async/failure) |
| `Effect.runSyncExit` | Sync effect → Exit (throws on async) |
## Key Composition Operators
### map - Transform Success Value
```typescript
Effect.succeed(5).pipe(Effect.map((n) => n * 2));
```
### flatMap / andThen - Chain Effects
```typescript
const getUser = (id: number) => Effect.succeed({ id, name: "Alice" });
const getPosts = (userId: number) => Effect.succeed([{ title: "Post 1" }]);
const program = getUser(1).pipe(Effect.flatMap((user) => getPosts(user.id)));
```
### tap - Side Effects Without Changing Value
```typescript
Effect.succeed(42).pipe(
Effect.tap((n) => Effect.log(`Got value: ${n}`)),
Effect.map((n) => n * 2),
);
```
### all - Combine Multiple Effects
```typescript
// Tuple of effects
const tuple = Effect.all([Effect.succeed(1), Effect.succeed("hello"), Effect.succeed(true)]); // Effect<[number, string, boolean], never, never>
// Object of effects
const obj = Effect.all({
id: Effect.succeed(1),
name: Effect.succeed("Alice"),
}); // Effect<{ id: number; name: string }, never, never>
```
## Effect vs Promise Comparison
| Promise | Effect |
| -------------------------------------- | -------------------------------- |
| `new Promise((resolve) => resolve(1))` | `Effect.succeed(1)` |
| `Promise.reject(error)` | `Effect.fail(error)` |
| `promise.then(f)` | `effect.pipe(Effect.map(f))` |
| `promise.then(f)` (f returns Promise) | `effect.pipe(Effect.flatMap(f))` |
| `Promise.all([...])` | `Effect.all([...])` |
| `await promise` | `yield* effect` (in Effect.gen) |
## Dual APIs
Most Effect functions support both "data-first" and "data-last" (pipeable) styles:
```typescript
// Data-last (pipeable) - recommended
Effect.succeed(1).pipe(Effect.map((n) => n + 1));
// Data-first
Effect.map(Effect.succeed(1), (n) => n + 1);
```
## Best Practices
### Do
1. **Use Effect.gen for sequential code** - More readable than nested flatMaps
2. **Use typed errors** - Always define error types with Schema.TaggedError
3. **Use Schema.parseJson for JSON** - Never use raw JSON.parse()
4. **Prefer data-last (pipeable)** - Consistent with Effect ecosystem
### Don't
1. **Don't mix async/await with Effect** - Use Effect.promise at boundaries only
2. **Don't use try/catch** - Use Effect.try or Effect.tryPromise
3. **Don't throw exceptions** - Use Effect.fail with typed errors
4. **Don't use JSON.parse** - Use Schema.parseJson with a schema
**For the complete list of mandatory patterns, forbidden anti-patterns, and idiomatic conventions, see the [Code Style](../code-style/SKILL.md) skill ([GitHub](https://github.com/andrueandersoncs/claude-skill-effect-ts/blob/main/skills/code-style/SKILL.md)).**
## Additional Resources
For comprehensive documentation on all Effect APIs, patterns, and advanced usage, consult the full Effect documentation at `${CLAUDE_PLUGIN_ROOT}/references/llms-full.txt`.
Search for these sections:
- "Effect vs Promise" for migration patterns
- "Getting Started" for installation and setup
- "Basic Concurrency" for parallel execution
- "Dual APIs" for function calling conventions
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.