effect-patterns-domain-modeling
БесплатноБез исполняемых скриптовНе проверенEffect-TS patterns for Domain Modeling. Use when working with domain modeling in Effect-TS applications.
от PaulJPhilp★ 807 звёзд на GitHubОб этом скилле
Effect-TS Patterns: Domain Modeling
This skill provides 15 curated Effect-TS patterns for domain modeling. Use this skill when working on tasks related to:
- domain modeling
- Best practices in Effect-TS applications
- Real-world patterns and solutions
🟢 Beginner Patterns
Create Type-Safe Errors
Rule: Use Data.TaggedError to create typed, distinguishable errors for your domain.
Good Example:
import { Effect, Data } from "effect"
// ============================================
// 1. Define tagged errors for your domain
// ============================================
class UserNotFoundError extends Data.TaggedError("UserNotFoundError")<{
readonly userId: string
}> {}
class InvalidEmailError extends Data.TaggedError("InvalidEmailError")<{
readonly email: string
readonly reason: string
}> {}
class DuplicateUserError extends Data.TaggedError("DuplicateUserError")<{
readonly email: string
}> {}
// ============================================
// 2. Use in Effect functions
// ============================================
interface User {
id: string
email: string
name: string
}
const validateEmail = (email: string): Effect.Effect<string, InvalidEmailError> => {
if (!email.includes("@")) {
return Effect.fail(new InvalidEmailError({
email,
reason: "Missing @ symbol"
}))
}
return Effect.succeed(email)
}
const findUser = (id: string): Effect.Effect<User, UserNotFoundError> => {
// Simulate database lookup
if (id === "123") {
return Effect.succeed({ id, email: "[email protected]", name: "Alice" })
}
return Effect.fail(new UserNotFoundError({ userId: id }))
}
const createUser = (
email: string,
name: string
): Effect.Effect<User, InvalidEmailError | DuplicateUserError> =>
Effect.gen(function* () {
const validEmail = yield* validateEmail(email)
// Simulate duplicate check
if (validEmail === "[email protected]") {
return yield* Effect.fail(new DuplicateUserError({ email: validEmail }))
}
return {
id: crypto.randomUUID(),
email: validEmail,
name,
}
})
// ============================================
// 3. Handle errors by tag
// ============================================
const program = createUser("[email protected]", "Alice").pipe(
Effect.catchTag("InvalidEmailError", (error) =>
Effect.succeed({
id: "fallback",
email: "[email protected]",
name: `${error.email} was invalid: ${error.reason}`,
})
),
Effect.catchTag("DuplicateUserError", (error) =>
Effect.fail(new Error(`Email ${error.email} already registered`))
)
)
// ============================================
// 4. Match on all errors
// ============================================
const handleAllErrors = createUser("bad-email", "Bob").pipe(
Effect.catchTags({
InvalidEmailError: (e) => Effect.succeed(`Invalid: ${e.reason}`),
DuplicateUserError: (e) => Effect.succeed(`Duplicate: ${e.email}`),
})
)
// ============================================
// 5. Run and see results
// ============================================
Effect.runPromise(program)
.then((user) => console.log("Created:", user))
.catch((error) => console.error("Failed:", error))
Rationale:
Create domain-specific errors using Data.TaggedError. Each error type gets a unique _tag for pattern matching.
Plain Error or string messages cause problems:
- No type safety - Can't know what errors a function might throw
- Hard to handle - Matching on error messages is fragile
- Poor documentation - Errors aren't part of the function signature
Tagged errors solve this by making errors typed and distinguishable.
Handle Missing Values with Option
Rule: Use Option instead of null/undefined to make missing values explicit and type-safe.
Good Example:
import { Option, Effect } from "effect"
// ============================================
// 1. Creating Options
// ============================================
// Some - a value is present
const hasValue = Option.some(42)
// None - no value
const noValue = Option.none<number>()
// From nullable - null/undefined becomes None
const fromNull = Option.fromNullable(null) // None
const fromValue = Option.fromNullable("hello") // Some("hello")
// ============================================
// 2. Checking and extracting values
// ============================================
const maybeUser = Option.some({ name: "Alice", age: 30 })
// Check if value exists
if (Option.isSome(maybeUser)) {
console.log(`User: ${maybeUser.value.name}`)
}
// Get with default
const name = Option.getOrElse(
Option.map(maybeUser, u => u.name),
() => "Anonymous"
)
// ============================================
// 3. Transforming Options
// ============================================
const maybeNumber = Option.some(5)
// Map - transform the value if present
const doubled = Option.map(maybeNumb
Установить effect-patterns-domain-modeling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл effect-patterns-domain-modeling?
Effect-TS patterns for Domain Modeling. Use when working with domain modeling in Effect-TS applications.
Как установить скилл effect-patterns-domain-modeling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл effect-patterns-domain-modeling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic