effect-pattern-matching

Implements exhaustive pattern matching for Effect discriminated unions using Data.TaggedEnum, $match, and Effect.match.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-pattern-matching-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-pattern-matching
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-pattern-matching
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-pattern-matching-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Manual _tag checks and if/else chains on discriminated unions in Effect TypeScript code are verbose, non-exhaustive, and error-prone, letting missing cases slip past the compiler. ## Core Features & Use Cases - ADT Construction with Data.TaggedEnum: Generates constructors, $match, and $is type guards automatically for tagged unions such as state machines, domain events, and result types. - Exhaustive Matching: Uses TaggedEnum.$match, Effect.match, Option.match, and Match.typeTags so the compiler enforces that every variant is handled. - Testable Matching: Replaces Date.now() and Math.random() inside match handlers with Clock and Random services for deterministic tests. - Use Case: When modeling a wallet connection state machine with Disconnected, Connecting, Connected, and Error states, define it with Data.taggedEnum and render UI text via $match so adding a new state produces compile errors at every incomplete match site. ## Quick Start Ask the AI to refactor a manually tagged union in your Effect TypeScript code into a Data.TaggedEnum with exhaustive $match handlers.

Frequently Asked Questions about effect-pattern-matching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I pattern match on discriminated unions in Effect TypeScript?

Define the union with Data.TaggedEnum and Data.taggedEnum, then call TaggedEnum.$match with a handler per variant. The compiler enforces exhaustiveness, so missing a case produces a type error.

What is the difference between Effect.match and Effect.result?

Effect.match handles success and failure declaratively in a pipeline with exhaustive handlers. Effect.result wraps the outcome in a Result that requires manual _tag checks, which are verbose and not compiler-enforced.

Does Data.TaggedEnum $is validate the full structure of a value?

No, $is only checks the _tag field, not the full structure. Use it for values created by your own constructors, and validate untrusted input with Schema before relying on $is as a structural guarantee.

How do I match on Schema unions in Effect?

Use Match.typeTags with a union built from Schema.TaggedStruct variants. Provide a handler object keyed by each tag, and the resulting matcher function refines types per branch with exhaustiveness checking.

Why is my pattern matching code hard to test?

Handlers calling Date.now() or Math.random() directly are non-deterministic. Replace them with the Clock and Random Effect services, then use TestClock in tests for controlled, repeatable results.