- Home
- Skills
- Andrueandersoncs
- Claude Skill Effect Ts
- Pattern Matching
pattern-matching_skill
- TypeScript
5
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill andrueandersoncs/claude-skill-effect-ts --skill pattern-matching- SKILL.md12.9 KB
Overview
This skill explains Effect's pattern matching primitives and how to replace imperative control flow with type-safe, exhaustive matches. It focuses on Match.value, Match.type, Match.tag, Match.when, Schema.is(), and related helpers to achieve compile-time guarantees and runtime clarity. Use it to learn conversions from if/else and switch to Match and to handle discriminated unions and Schema.TaggedClass values.
How this skill works
Match builds composable matchers that narrow types per branch and enforce exhaustive handling. Use Match.value for raw values, Match.type to create reusable matchers, Match.tag to match discriminated union tags, and Match.when for predicates and Schema.is() refinements. Combine Match.exhaustive or Match.orElse to assert completeness or provide fallbacks; Match.pipe composition keeps logic declarative and testable.
When to use it
- Replace if/else chains and ternaries with Match.value + Match.when
- Convert switch/case over union types to Match.type + Match.tag
- Handle discriminated unions, errors, and domain states exhaustively
- Access class methods or runtime-validated shapes using Schema.is() inside Match.when
- Create reusable decision logic with Match.type for repeated patterns
Best practices
- Always prefer Match.exhaustive to catch missing cases at compile time
- Use Match.tag for simple _tag-based unions and Schema.is() when you need class methods or validation
- Refactor imperative conditionals immediately — idiomatic Effect avoids if/else and switch
- Use Match.when with type predicates or Schema.is() to perform safe refinements
- Build reusable matchers via Match.type().pipe(...) for clarity and reuse
Example use cases
- Convert a status if/else chain to Match.type<Status>().pipe(..., Match.exhaustive)
- Match runtime-parsed JSON to Schema.TaggedClass via Schema.is() and use class methods in branches
- Handle domain errors by matching AppError union with Match.tag and return Effects for each error case
- Implement state machines (Draft/Published/Archived) with Schema.TaggedClass and exhaustive Match.when branches
- Replace ad-hoc null/error checks with Option.match, Either.match, or Effect.match paired with Match helpers
FAQ
Effect idioms enforce pattern matching to get compile-time exhaustiveness and safer type narrowing; refactoring conditional logic to Match removes classes of runtime bugs.
When should I use Schema.is() vs Match.tag?
Use Match.tag for simple pattern matching on a discriminant when only raw data is needed. Use Schema.is() inside Match.when when you need runtime validation, class methods, or richer type narrowing.