Token导航 LogoToken导航

Agent Skill · 研究检索

pattern-matching(模式匹配)

pattern-matching 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

pattern-matching 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为权限未标注;许可证为 MIT,暂无第三方扫描结果,按安装量在研究检索类的 73,675 个 Skill 里排第 58,252。

总安装 419周安装 18GitHub Stars 公开资料未说明下载 147核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:pattern-matching(模式匹配)
来源仓库:https://github.com/front-depiction/claude-setup
仓库路径:skills/pattern-matching
安装命令:
npx skills add front-depiction/claude-setup --skill "pattern-matching"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add front-depiction/claude-setup --skill "pattern-matching"

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于发现并安装 AI 代理技能。适合扩展 Codex、Claude 等宿主功能。可自动化技能管理与部署。pattern-matching 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

安装命令:npx skills add front-depiction/claude-setup --skill "pattern-matching 注意技能来源可信度及潜在联网行为。

来源仓库内路径:skills/pattern-matching

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add front-depiction/claude-setup --skill "pattern-matching";命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    权限没有明确标注,第一次使用时只给一个无关紧要的任务,观察它到底读了哪些文件和网络。

常见问题

6 条

pattern-matching 怎么安装?

在终端执行 npx skills add front-depiction/claude-setup --skill "pattern-matching"。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

pattern-matching 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

pattern-matching 需要什么权限?

权限级别没有明确标注。第一次使用时建议只给无关紧要的任务,观察它实际读写了哪些内容。

pattern-matching 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

pattern-matching 用的人多吗?

公开数据是累计安装 419 次,近一周安装 18 次,下载 147 次。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

pattern-matching 安全吗?

没有查到第三方扫描结果,安全性无法从公开资料判断,安装前请自行审查源码、依赖和命令行为。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 许可证明确为 MIT,商用和分发边界好判断。

先想清楚的地方

  • 没有第三方扫描结果,安全性只能靠自己读源码判断。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 要求有安全扫描结论才肯安装的团队。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
pattern-matching

模式匹配 · 本页

419—权限未标注MIT未收录

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

name
pattern-matching
description
Master Effect pattern matching using Data.TaggedEnum, $match, $is, Match.typeTags, and Effect.match. Avoid manual _tag checks and Effect.either patterns. Use this skill when working with discriminated unions, ADTs, or conditional logic based on tagged types.

Effect Pattern Matching Skill

Use this skill when working with discriminated unions, ADTs, conditional logic, or any type that uses _tag discrimination. Pattern matching provides exhaustive, type-safe alternatives to imperative conditionals.

Core Philosophy

Pattern matching over imperative conditionals:

  • Exhaustive by default (compiler enforces all cases)
  • Type-safe refinement in each branch
  • Declarative, not imperative
  • Pipeline-friendly composition

Pattern 1: Data.TaggedEnum for ADTs

Use Data.TaggedEnum instead of manual tagged unions.

The Problem: Manual Tagged Unions

// ❌ WRONG - Manual tagged union
type WalletState =
  | { readonly _tag: "Disconnected" }
  | { readonly _tag: "Connecting" }
  | { readonly _tag: "Connected"; readonly address: string }
  | { readonly _tag: "Error"; readonly message: string }

// Manual constructors - verbose and error-prone
const disconnected = (): WalletState => ({ _tag: "Disconnected" })
const connecting = (): WalletState => ({ _tag: "Connecting" })
const connected = (address: string): WalletState =>
  ({ _tag: "Connected", address })
const error = (message: string): WalletState =>
  ({ _tag: "Error", message })

// No built-in pattern matching
// No type guards
// No exhaustiveness checking

The Solution: Data.TaggedEnum

// ✅ CORRECT - TaggedEnum with constructors + $match + $is
import { Data } from "effect"

type WalletState = Data.TaggedEnum<{
  Disconnected: {}
  Connecting: {}
  Connected: { readonly address: string }
  Error: { readonly message: string }
}>

const WalletState = Data.taggedEnum<WalletState>()

/**
 * WalletState now provides:
 * - WalletState.Disconnected() - Constructor
 * - WalletState.Connecting() - Constructor
 * - WalletState.Connected({ address }) - Constructor
 * - WalletState.Error({ message }) - Constructor
 * - WalletState.$match(state, { ... }) - Pattern matching
 * - WalletState.$is("Connected")(state) - Type guard
 */

// Usage
const state = WalletState.Connected({ address: "0x123" })

// Pattern match
const display = WalletState.$match(state, {
  Disconnected: () => "Please connect wallet",
  Connecting: () => "Connecting...",
  Connected: ({ address }) => `Connected: ${address}`,
  Error: ({ message }) => `Error: ${message}`
})

// Type guard
if (WalletState.$is("Connected")(state)) {
  console.log(state.address) // Type-safe access
}

Benefits of Data.TaggedEnum

  1. Automatic constructors - No manual factory functions
  2. Automatic $match - Exhaustive pattern matching built-in
  3. Automatic $is - Type-safe guards for each variant
  4. Type inference - Compiler knows all variants
  5. Compile-time exhaustiveness - Forget a case? Compiler error

When to Use Data.TaggedEnum

  • State machines: Connection states, loading states, workflow states
  • Domain events: UserLoggedIn, UserLoggedOut, SessionExpired
  • Command types: CreateUser, UpdateUser, DeleteUser
  • Result types: Success, Failure, Pending
  • Any discriminated union with multiple variants

Pattern 2: Avoid Effect.either + _tag Checks

Use Effect.match instead of Effect.either with manual tag checks.

The Problem: Effect.either with Manual Checks

// ❌ WRONG - Effect.either with manual _tag checks
import { Effect, Either, Data } from "effect"

declare const User: { name: string; id: string }
type User = typeof User

class NotFound extends Data.TaggedError("NotFound")<{
  readonly id: string
}> {}

const getUser = (id: string): Effect.Effect<User, NotFound> => Effect.fail(new NotFound({ id }))

const program = Effect.gen(function* () {
  const result = yield* Effect.either(getUser("123"))

  // Manual tag checking - not exhaustive
  if (result._tag === "Left") {
    console.error(`User not found: ${result.left.id}`)
    return null
  }

  return result.right
})

Problems:

  • Not exhaustive (could forget Right case)
  • Verbose and imperative
  • Breaks pipeline style
  • Manual unwrapping of Either

The Solution: Effect.match

// ✅ CORRECT - Effect.match for declarative error handling
import { Effect, Data } from "effect"

declare const User: { name: string; id: string }
type User = typeof User

class NotFound extends Data.TaggedError("NotFound")<{
  readonly id: string
}> {}

const getUser = (id: string): Effect.Effect<User, NotFound> => Effect.fail(new NotFound({ id }))

const program = getUser("123").pipe(
  Effect.match({
    onFailure: (error) => {
      console.error(`User not found: ${error.id}`)
      return null
    },
    onSuccess: (user) => user
  })
)

Benefits:

  • Exhaustive (must handle both cases)
  • Declarative and pipeline-friendly
  • No manual Either unwrapping
  • Type-safe refinement in each branch

Effect.match Variants

import { Effect, Cause } from "effect"

declare const effect: Effect.Effect<unknown, unknown, unknown>
declare function handleError(error: unknown): unknown
declare function handleSuccess(value: unknown): unknown
declare function handleCause(cause: Cause.Cause<unknown>): unknown

// Basic match - transform both success and failure
Effect.match(effect, {
  onFailure: (error) => handleError(error),
  onSuccess: (value) => handleSuccess(value)
})

// matchEffect - return Effects from handlers
Effect.matchEffect(effect, {
  onFailure: (error) => Effect.logError(error).pipe(Effect.as(null)),
  onSuccess: (value) => Effect.succeed(value)
})

// matchCause - match on full Cause (errors + defects + interrupts)
Effect.matchCause(effect, {
  onFailure: (cause) => handleCause(cause),
  onSuccess: (value) => value
})

// matchCauseEffect - Cause matching with Effect handlers
Effect.matchCauseEffect(effect, {
  onFailure: (cause) => Effect.logError(cause).pipe(Effect.as(null)),
  onSuccess: (value) => Effect.succeed(value)
})

Pattern 3: Use $match for Exhaustive Pattern Matching

Use TaggedEnum.$match for exhaustive, type-safe pattern matching.

The Problem: if/else Chains

// ❌ WRONG - if/else chains, not exhaustive
import { Data } from "effect"

type Status = Data.TaggedEnum<{
  Active: {}
  Expired: {}
  Revoked: {}
}>
const Status = Data.taggedEnum<Status>()

const getColor = (status: Status): string => {
  if (status._tag === "Active") {
    return "green"
  } else if (status._tag === "Expired") {
    return "yellow"
  }
  // Forgot "Revoked" - no compiler error!
  return "gray"
}

Problems:

  • Not exhaustive (easy to forget cases)
  • Compiler doesn't enforce completeness
  • Imperative style
  • Hard to refactor when adding variants

The Solution: $match

// ✅ CORRECT - $match with exhaustive checking
import { Data } from "effect"

type Status = Data.TaggedEnum<{
  Active: {}
  Expired: {}
  Revoked: {}
}>
const Status = Data.taggedEnum<Status>()

const getColor = (status: Status): string =>
  Status.$match(status, {
    Active: () => "green",
    Expired: () => "yellow",
    Revoked: () => "red"
    // Compiler error if any case is missing!
  })

Benefits:

  • Exhaustive - Compiler enforces all cases
  • Type-safe - Each handler gets refined type
  • Declarative - Clear mapping from variant to result
  • Refactor-safe - Add variant? Compiler finds all matches to update

$match with Data Access

type AsyncState = Data.TaggedEnum<{
  Idle: {}
  Loading: {}
  Success: { readonly data: string }
  Failure: { readonly error: string }
}>
const AsyncState = Data.taggedEnum<AsyncState>()

const display = (state: AsyncState): string =>
  AsyncState.$match(state, {
    Idle: () => "Not started",
    Loading: () => "Loading...",
    Success: ({ data }) => `Loaded: ${data}`,
    Failure: ({ error }) => `Error: ${error}`
  })

Nested Pattern Matching

type Request = Data.TaggedEnum<{
  Pending: {}
  Approved: { readonly by: string }
  Rejected: { readonly reason: string }
}>
const Request = Data.taggedEnum<Request>()

type Workflow = Data.TaggedEnum<{
  Draft: { readonly request: Request }
  Submitted: { readonly request: Request }
  Completed: {}
}>
const Workflow = Data.taggedEnum<Workflow>()

const getStatus = (workflow: Workflow): string =>
  Workflow.$match(workflow, {
    Draft: ({ request }) =>
      Request.$match(request, {
        Pending: () => "Draft - Pending",
        Approved: ({ by }) => `Draft - Approved by ${by}`,
        Rejected: ({ reason }) => `Draft - Rejected: ${reason}`
      }),
    Submitted: ({ request }) =>
      Request.$match(request, {
        Pending: () => "Submitted - Awaiting approval",
        Approved: ({ by }) => `Submitted - Approved by ${by}`,
        Rejected: ({ reason }) => `Submitted - Rejected: ${reason}`
      }),
    Completed: () => "Completed"
  })

Pattern 4: Use $is for Single-Case Type Guards

Use TaggedEnum.$is instead of manual _tag checks.

The Problem: Manual _tag Checks

// ❌ WRONG - Manual tag checking
import { Data } from "effect"

type Status = Data.TaggedEnum<{
  Active: {}
  Expired: {}
}>
const Status = Data.taggedEnum<Status>()

// Verbose and repetitive
const status = Status.Active()
if (status._tag === "Active") {
  console.log("Active!")
}

// Hard to use in Array methods
const items: Status[] = [Status.Active(), Status.Expired()]
const activeItems = items.filter(item => item._tag === "Active")

The Solution: $is Type Guards

// ✅ CORRECT - $is for type-safe guards
import { Data, Array, pipe } from "effect"

type Status = Data.TaggedEnum<{
  Active: {}
  Expired: {}
}>
const Status = Data.taggedEnum<Status>()

const status = Status.Active()

// Clean, declarative guard
if (Status.$is("Active")(status)) {
  console.log("Active!")
}

// Perfect for Array methods
const items: Status[] = [Status.Active(), Status.Expired()]
const activeItems = items.filter(Status.$is("Active"))

// Pipeline-friendly
const hasActive = pipe(
  items,
  Array.some(Status.$is("Active"))
)

// Multiple guards
const activeOrExpired = items.filter(
  item => Status.$is("Active")(item) || Status.$is("Expired")(item)
)

$is in Effect Pipelines

import { Data, pipe } from "effect"

type LoadState = Data.TaggedEnum<{
  Loading: {}
  Ready: { readonly data: string[] }
  Error: { readonly message: string }
}>
const LoadState = Data.taggedEnum<LoadState>()

const getData = (state: LoadState): string[] =>
  pipe(
    state,
    // Type guard refines to Ready
    LoadState.$is("Ready"),
    // Now can access .data safely
    ready => ready ? ready.data : []
  )

Pattern 5: Use Option.match Instead of _tag Checks

Use Option.match instead of manual ._tag checks on Options.

The Problem: Manual Option Tag Checks

// ❌ WRONG - Manual Option._tag checks
import { Option } from "effect"

type User = { name: string; id: string }

const maybeUser: Option.Option<User> = Option.some({ name: "Alice", id: "123" })

// Imperative and verbose
if (maybeUser._tag === "Some") {
  console.log(maybeUser.value.name)
} else {
  console.log("No user")
}

The Solution: Option.match

// ✅ CORRECT - Option.match
import { Option, pipe } from "effect"

type User = { name: string; id: string }

const maybeUser: Option.Option<User> = Option.some({ name: "Alice", id: "123" })

const display = Option.match(maybeUser, {
  onNone: () => "No user",
  onSome: (user) => user.name
})

// In pipelines
const name = pipe(
  maybeUser,
  Option.match({
    onNone: () => "Guest",
    onSome: (user) => user.name
  })
)

Option Pattern Matching Variants

import { Option, pipe } from "effect"

declare const option: Option.Option<string>
declare const defaultValue: string
declare function transform(value: string): string
declare function predicate(value: string): boolean

// Basic match
Option.match(option, {
  onNone: () => defaultValue,
  onSome: (value) => transform(value)
})

// getOrElse - simpler for just default value
Option.getOrElse(option, () => defaultValue)

// map + getOrElse pattern
pipe(
  option,
  Option.map(transform),
  Option.getOrElse(() => defaultValue)
)

// filter + match
pipe(
  option,
  Option.filter(predicate),
  Option.match({
    onNone: () => "Filtered out or was None",
    onSome: (value) => `Matched: ${value}`
  })
)

Pattern 6: Use Match.typeTags for Schema Unions

For Schema-based unions, use Match.typeTags for pattern matching.

Schema Union Pattern Matching

import { Schema, Match } from "effect"

// Schema-based tagged structs
const Admin = Schema.TaggedStruct("Admin", {
  id: Schema.String,
  permissions: Schema.Array(Schema.String)
}).pipe(Schema.Data)

const Customer = Schema.TaggedStruct("Customer", {
  id: Schema.String,
  tier: Schema.Literal("free", "premium")
}).pipe(Schema.Data)

const User = Schema.Union(Admin, Customer)
type User = Schema.Schema.Type<typeof User>

// Match.typeTags for Schema unions
const getPermissions = Match.typeTags<User>()({
  Admin: ({ permissions }) => permissions,
  Customer: ({ tier }) => tier === "premium" ? ["read"] : []
})

const user: User = {
  _tag: "Admin" as const,
  id: "1",
  permissions: ["read", "write"]
}

const perms = getPermissions(user) // ["read", "write"]

Match.typeTags Pattern

import { Match, Data } from "effect"

type UnionType = Data.TaggedEnum<{
  VariantA: { field: string }
  VariantB: { other: number }
}>

declare const value: UnionType
declare function handleA(data: { field: string }): string
declare function handleB(data: { other: number }): string

// Create matcher function
const match = Match.typeTags<UnionType>()

// Use with handlers object
const result = match({
  VariantA: (data) => handleA(data),
  VariantB: (data) => handleB(data)
})(value)

// Or create matcher and apply later
const matcher = match({
  VariantA: (data) => handleA(data),
  VariantB: (data) => handleB(data)
})
const result2 = matcher(value)

Pattern 7: Loadable.match for Async State

Use Loadable.match for async state pattern matching.

Loadable Pattern

import { Loadable } from "@/typeclass/Loadable"

type User = { name: string; id: string }

declare const Spinner: () => JSX.Element
declare const UserProfile: (props: { user: User }) => JSX.Element
declare const ErrorDisplay: (props: { error: Error }) => JSX.Element

type UserData = Loadable.Loadable<User>

const display = (data: UserData): JSX.Element =>
  Loadable.match(data, {
    onPending: () => <Spinner />,
    onReady: (user) => <UserProfile user={user} />
  })

// With error state
type UserDataWithError = Loadable.LoadableWithError<User, Error>

const displayWithError = (data: UserDataWithError): JSX.Element =>
  Loadable.matchWithError(data, {
    onPending: () => <Spinner />,
    onReady: (user) => <UserProfile user={user} />,
    onError: (error) => <ErrorDisplay error={error} />
  })

Testability: Effect Services

When pattern matching involves non-deterministic operations, use Effect services.

The Problem: Untestable Direct Calls

// ❌ WRONG - untestable
import { Data } from "effect"

type State = Data.TaggedEnum<{
  Active: {}
  Expired: {}
}>
const State = Data.taggedEnum<State>()

const processState = (state: State): string =>
  State.$match(state, {
    Active: () => `Active at ${Date.now()}`,
    Expired: () => `Expired at ${Date.now()}`
  })

The Solution: Effect Services

// ✅ CORRECT - testable with Clock service
import { Clock, Effect, Data, TestClock } from "effect"

type State = Data.TaggedEnum<{
  Active: {}
  Expired: {}
}>
const State = Data.taggedEnum<State>()

const processState = (state: State): Effect.Effect<string> =>
  Effect.gen(function* () {
    const now = yield* Clock.currentTimeMillis

    return State.$match(state, {
      Active: () => `Active at ${now}`,
      Expired: () => `Expired at ${now}`
    })
  })

// In tests, use TestClock for deterministic time
const testProgram = processState(State.Active()).pipe(
  Effect.provide(TestClock.make())
)

Random Values in Pattern Matching

// ❌ WRONG - untestable
import { Data } from "effect"

type User = Data.TaggedEnum<{
  Admin: {}
  Customer: {}
}>
const User = Data.taggedEnum<User>()

const assignColor = (user: User): string =>
  User.$match(user, {
    Admin: () => "red",
    Customer: () => Math.random() > 0.5 ? "blue" : "green"
  })

// ✅ CORRECT - testable with Random service
import { Random, Effect } from "effect"

const assignColorTestable = (user: User): Effect.Effect<string> =>
  User.$match(user, {
    Admin: () => Effect.succeed("red"),
    Customer: () =>
      Effect.gen(function* () {
        const rand = yield* Random.next
        return rand > 0.5 ? "blue" : "green"
      })
  })

Complete Example: Wallet Connection State Machine

import { Data, Effect, Clock } from "effect"

// Define state machine with TaggedEnum
type WalletState = Data.TaggedEnum<{
  Disconnected: {}
  Connecting: { readonly startedAt: number }
  Connected: {
    readonly address: string
    readonly connectedAt: number
  }
  Error: {
    readonly message: string
    readonly occurredAt: number
  }
}>

const WalletState = Data.taggedEnum<WalletState>()

// State transitions
const connect = (): Effect.Effect<WalletState> =>
  Effect.gen(function* () {
    const now = yield* Clock.currentTimeMillis
    return WalletState.Connecting({ startedAt: now })
  })

const completeConnection = (
  address: string
): Effect.Effect<WalletState> =>
  Effect.gen(function* () {
    const now = yield* Clock.currentTimeMillis
    return WalletState.Connected({
      address,
      connectedAt: now
    })
  })

const fail = (message: string): Effect.Effect<WalletState> =>
  Effect.gen(function* () {
    const now = yield* Clock.currentTimeMillis
    return WalletState.Error({
      message,
      occurredAt: now
    })
  })

// Pattern match for display
const displayState = (state: WalletState): string =>
  WalletState.$match(state, {
    Disconnected: () => "Please connect your wallet",
    Connecting: ({ startedAt }) =>
      `Connecting... (started at ${startedAt})`,
    Connected: ({ address, connectedAt }) =>
      `Connected: ${address} (at ${connectedAt})`,
    Error: ({ message, occurredAt }) =>
      `Error: ${message} (at ${occurredAt})`
  })

// Type-safe state queries using $is
const isConnected = WalletState.$is("Connected")
const canDisconnect = (state: WalletState): boolean =>
  isConnected(state) || WalletState.$is("Error")(state)

// Filter connected states
const getConnectedStates = (
  states: WalletState[]
): Array<Extract<WalletState, { _tag: "Connected" }>> =>
  states.filter(isConnected)

Quality Checklist

Before completing pattern matching implementation:

  • [ ] Use Data.TaggedEnum for ADTs (not manual tagged unions)
  • [ ] Use TaggedEnum.$match for exhaustive matching
  • [ ] Use TaggedEnum.$is for type guards (not ._tag === )
  • [ ] Use Effect.match instead of Effect.either + if checks
  • [ ] Use Option.match instead of Option._tag checks
  • [ ] Use Match.typeTags for Schema union matching
  • [ ] All pattern matches are exhaustive (compiler-checked)
  • [ ] Use Clock service instead of Date.now() in matches
  • [ ] Use Random service instead of Math.random() in matches
  • [ ] Pattern matching is declarative (no imperative conditionals)
  • [ ] Pipeline-friendly composition
  • [ ] Type-safe refinement in each branch

Common Patterns Summary

ADT Definition

import { Data } from "effect"

type State = Data.TaggedEnum<{
  VariantA: { field: string }
  VariantB: { other: number }
}>
const State = Data.taggedEnum<State>()

Exhaustive Matching

import { Data } from "effect"

type State = Data.TaggedEnum<{
  VariantA: { field: string }
  VariantB: { other: number }
}>
const State = Data.taggedEnum<State>()

declare const state: State
declare function handleA(field: string): void
declare function handleB(other: number): void

State.$match(state, {
  VariantA: ({ field }) => handleA(field),
  VariantB: ({ other }) => handleB(other)
})

Type Guards

import { Data } from "effect"

type State = Data.TaggedEnum<{
  VariantA: { field: string }
  VariantB: { other: number }
}>
const State = Data.taggedEnum<State>()

declare const state: State
declare const items: State[]

if (State.$is("VariantA")(state)) {
  // state is refined to VariantA
}

// In filters
items.filter(State.$is("VariantA"))

Effect Matching

import { Effect } from "effect"

declare const effect: Effect.Effect<unknown, unknown, unknown>
declare function handleError(error: unknown): unknown
declare function handleSuccess(value: unknown): unknown

effect.pipe(
  Effect.match({
    onFailure: (error) => handleError(error),
    onSuccess: (value) => handleSuccess(value)
  })
)

Option Matching

import { Option } from "effect"

declare const option: Option.Option<string>
declare const defaultValue: string
declare function transform(value: string): string

Option.match(option, {
  onNone: () => defaultValue,
  onSome: (value) => transform(value)
})

Your pattern matching implementations should be exhaustive, type-safe, declarative, and testable.

平台分布

Claude Code

31.46%
按下载量换算46

windsurf

24.73%
按下载量换算36

trae

18.34%
按下载量换算27

OpenCode

11.41%
按下载量换算17

Codex

7.78%
按下载量换算11

Antigravity

3.26%
按下载量换算5

安全审计

暂无安全审计结果可展示。

权限和风险

权限未标注

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills