fp-ts-pragmatic – skill Lập trình cho agent AI
Hướng dẫn thực tế, không biệt ngữ về lập trình hàm với fp-ts - cách tiếp cận 80/20 mang lại kết quả mà không cần lý thuyết hàn lâm. Dùng khi viết TypeScript với thư viện fp-ts.
Cài skill fp-ts-pragmatic 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-ts-pragmatic-e5c2f.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /fp-ts-pragmatic – 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-ts-pragmatic-e5c2f.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $fp-ts-pragmatic – 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-ts-pragmatic-e5c2f.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /fp-ts-pragmatic – 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-ts-pragmatic-e5c2f.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /fp-ts-pragmatic – 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.
Pragmatic Functional Programming
Read this first. This guide cuts through the academic jargon and shows you what actually matters. No category theory. No abstract nonsense. Just patterns that make your code better.
Detailed Guide
Read [the detailed guide](references/detailed-guide.md) before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.
When to Use This Skill
- When starting with fp-ts and need practical guidance
- When writing TypeScript code that handles nullable values, errors, or async operations
- When you want cleaner, more maintainable functional code without the academic overhead
- When refactoring imperative code to functional style
When NOT to Use FP
Functional programming is not always the answer. Here's when to keep it simple.
Simple Null Checks
// Just use optional chaining - it's built into the language
const city = user?.address?.city ?? 'Unknown'
// DON'T overcomplicate it
const city = pipe(
O.fromNullable(user),
O.flatMap(u => O.fromNullable(u.address)),
O.flatMap(a => O.fromNullable(a.city)),
O.getOrElse(() => 'Unknown')
)Simple Loops
// A for loop is fine when you need early exit or complex logic
function findFirst(items: Item[], predicate: (i: Item) => boolean): Item | null {
for (const item of items) {
if (predicate(item)) return item
}
return null
}
// DON'T force FP when it doesn't help
const result = pipe(
items,
A.findFirst(predicate),
O.toNullable
)Performance-Critical Code
// For hot paths, benchmark both implementations on the actual runtime
function sumLarge(numbers: number[]): number {
let sum = 0
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i]
}
return sum
}
// A.reduce does not create an intermediate array per item; callbacks still have runtime costs
const sum = pipe(numbers, A.reduce(0, (acc, n) => acc + n))When Your Team Doesn't Know FP
If you're the only one who can read the code, it's not good code.
// If your team knows this pattern
async function getUser(id: string): Promise<User | null> {
try {
const response = await fetch(`/api/users/${encodeURIComponent(id)}`)
if (!response.ok) return null
return await response.json()
} catch {
return null
}
}
// Don't force this on them
const getUser = (id: string): TE.TaskEither<Error, User> =>
pipe(
TE.tryCatch(() => fetch(`/api/users/${encodeURIComponent(id)}`), E.toError),
TE.flatMap(r => r.ok ? TE.right(r) : TE.left(new Error('Not found'))),
TE.flatMap(r => TE.tryCatch(() => r.json(), E.toError))
)---
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.
Skill liên quan
- fp-ts-react – Mẫu thực tế dùng fp-ts với React - hooks, state, form, lấy dữ liệu. Dùng khi xây dựng…
- framework-migration-code-migrate – Bạn là chuyên gia di chuyển code, chuyên chuyển đổi codebase giữa các framework, ngôn…
- framework-migration-deps-upgrade – Bạn là chuyên gia quản lý dependency, chuyên nâng cấp an toàn và từng bước các…
- self-eval – Đánh giá trung thực chất lượng công việc của AI bằng hệ thống chấm điểm hai trục. Dùng…
- frontend-architecture – Kiến trúc frontend độc lập framework, áp dụng cho mọi ứng dụng React hoặc React Native…
- frontend-developer – Xây dựng component React, triển khai bố cục responsive và xử lý quản lý state phía…
- senior-architect – Skill này nên được dùng khi người dùng yêu cầu “thiết kế kiến trúc hệ thống”, “đánh giá…
- senior-backend – Thiết kế và triển khai hệ thống backend gồm REST API, microservices, kiến trúc cơ sở dữ…