pattern-matching

Match Effect-TS discriminated unions with Data.TaggedEnum and $match.

68|13|Updated Aug 9, 2025
One-click install
npx skills add https://github.com/kriegcloud/beep-effect --skill pattern-matching-kriegcloud
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pattern-matching
Source: https://github.com/kriegcloud/beep-effect/tree/main/.repos/beep-effect/.cursor/skills/pattern-matching
Command: npx skills add https://github.com/kriegcloud/beep-effect --skill pattern-matching-kriegcloud

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you avoid manual _tag checks and verbose Effect.either patterns when working with discriminated unions, ADTs, and conditional logic in Effect-TS, leading to more robust and readable code.

Core Features & Use Cases

  • Type-Safe Discriminated Unions: Leverage Data.TaggedEnum for automatic constructors, pattern matching ($match), and type guards ($is).
  • Declarative Error Handling: Use Effect.match for clean, pipeline-friendly handling of success and failure cases.
  • Use Case: Refactor complex if/else chains or manual _tag checks in your state management or API response handling to use Effect's built-in, type-safe pattern matching constructs.

Quick Start

Use the pattern-matching skill to refactor the provided WalletState type to use Data.TaggedEnum and its associated pattern matching functions.

Frequently Asked Questions about pattern-matching

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

FAQPage Schema
How do I handle discriminated unions in Effect-TS without manual _tag checks?

Pattern matching in Effect-TS eliminates manual _tag checks by using `Data.TaggedEnum` to generate automatic constructors, type guards (`$is`), and the `$match` function for declarative logic. This approach replaces verbose conditional chains with exhaustive, type-safe code.

What is the best way to refactor imperative if/else chains for state management in Effect?

The best way to refactor imperative if/else chains is using `Effect.match` and `$match` for declarative state management. This transitions your code to a pipeline-friendly structure that handles success and failure cases cleanly while ensuring exhaustive type safety.

How do I use Effect.match for declarative error handling in pipelines?

Use `Effect.match` for declarative error handling by defining success and failure callbacks within your pipeline. This replaces verbose `Effect.either` patterns, allowing you to handle errors cleanly and maintain a pipeline-friendly, type-safe flow.

Does pattern matching in Effect-TS enforce exhaustive checks for API response handling?

Yes, pattern matching enforces exhaustive checks for API response handling. Using `Match.typeTags` and `$match` ensures all possible discriminated union states are handled, preventing unhandled cases during data transformation or state transitions.

When should I use Option.match instead of manual conditional logic in Effect?

Use `Option.match` instead of manual conditional logic when handling optional values within Effect pipelines. It provides a declarative, type-safe way to handle presence and absence, avoiding imperative if/else checks and improving code readability.