fp-either-ref – skill Khác cho agent AI
Tài liệu tham khảo nhanh về kiểu Either. Dùng khi cần xử lý lỗi, validation hoặc các thao tác có thể thất bại với lỗi có kiểu.
Cài skill fp-either-ref bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-either-ref-c4389.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /fp-either-ref – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-either-ref-c4389.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $fp-either-ref – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-either-ref-c4389.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /fp-either-ref – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-either-ref-c4389.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /fp-either-ref – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Either Quick Reference
Either = success or failure. Right(value) or Left(error).
When to Use
- You need a quick fp-ts reference for typed synchronous error handling.
- The task involves validation, fallible operations, or converting throwing code to
Either. - You want a compact cheat sheet rather than a long tutorial.
Create
import * as E from 'fp-ts/Either'
E.right(value) // Success
E.left(error) // Failure
E.fromNullable(err)(x) // null → Left(err), else Right(x)
E.tryCatch(fn, toError) // try/catch → EitherTransform
E.map(fn) // Transform Right value
E.mapLeft(fn) // Transform Left error
E.flatMap(fn) // Chain (fn returns Either)
E.filterOrElse(pred, toErr) // Right → Left if pred failsExtract
E.getOrElse(err => fallbackValue) // Get Right or default
E.match(onLeft, onRight) // Pattern match
E.toUnion(either) // E | A (loses type info)Common Patterns
import { pipe, identity } from 'fp-ts/function'
import * as E from 'fp-ts/Either'
// Toy validation; an @ check is not complete email validation
const validateEmail = (s: string): E.Either<string, string> =>
s.includes('@') ? E.right(s) : E.left('Invalid email')
// Chain validations (stops at first error)
pipe(
E.right({ email: '[email protected]', age: 25 }),
E.flatMap(d => pipe(validateEmail(d.email), E.map(() => d))),
E.flatMap(d => d.age >= 18 ? E.right(d) : E.left('Must be 18+'))
)
// Convert throwing code
const parseJson = (s: string) => E.tryCatch(
() => JSON.parse(s),
(e) => `Parse error: ${e}`
)vs try/catch
// ❌ try/catch - errors not in types
try {
const data = JSON.parse(input)
process(data)
} catch (e) {
handleError(e)
}
// ✅ Either - errors explicit in types
pipe(
E.tryCatch(() => JSON.parse(input), String),
E.flatMap(data => E.tryCatch(() => process(data), String)),
E.match(handleError, identity)
)Use Either when error type matters and you want to chain operations.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Reference scope
These are fp-ts 2.x fragments. Supply application variables, types, validators and imports, and check the installed version. map does not catch thrown exceptions. Task has no typed error channel; an improperly wrapped promise can still reject. Use tryCatch at fallible boundaries.
Official API: [fp-ts modules](https://gcanti.github.io/fp-ts/modules/).
Skill liên quan
- fp-types-ref – Tài liệu tham khảo nhanh về các kiểu fp-ts. Dùng khi người dùng hỏi nên dùng kiểu nào…
- fxmacrodata – Truy vấn FXMacroData để lấy chỉ số kinh tế vĩ mô từ nguồn chính thức, lịch công bố, lãi…
- gamification-engine – Sổ đăng ký điểm gamification: người chơi và phòng ban, số dư điểm và điểm kiếm được…
- geminiignore-finops – Cấu hình và tối ưu file .geminiignore để tăng hiệu quả context window của AI và giảm chi…
- geo-citability – Chấm điểm và tối ưu khả năng được AI trích dẫn (AI citability).
- geo-compare – Theo dõi biến động hằng tháng và báo cáo tiến độ cho khách hàng GEO.
- geo-fundamentals – Generative Engine Optimization cho các công cụ tìm kiếm AI (ChatGPT, Claude, Perplexity).
- geo-keyword-expansion-tool – Công cụ mở rộng từ khóa GEO. Dùng khi làm việc với từ khóa gốc và địa điểm mục tiêu.