Chuyển đến nội dung
Skillpedia
Lập trình chung48k · #4645

fp-pragmatic

Skill này làm gì

Hướng dẫn này dạy các khái niệm cốt lõi của lập trình hàm theo cách thực tế, tập trung vào những gì thật sự quan trọng để cải thiện mã nguồn của bạn mà không bị rối.

Khi nào nên dùng

  • ✓Khi bắt đầu tìm hiểu lập trình hàm trong TypeScript.
  • ✓Khi muốn khám phá nhanh các ý tưởng lập trình hàm (cách tiếp cận 80/20).
  • ✓Khi muốn hiểu lúc nào lập trình hàm hữu ích và lúc nào nên giữ mã đơn giản.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-pragmatic/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-pragmatic/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để tôi bắt đầu với lập trình hàm trong TypeScript một cách đơn giản?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Hướng dẫn tập trung vào các mẫu hữu ích và tránh thuật ngữ hàn lâm, chỉ cách áp dụng những khái niệm mang lại kết quả thực tế.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết 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 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

  • You want a pragmatic starting point for fp-ts or functional programming in TypeScript.
  • The task is exploratory or educational and needs an 80/20 view of what is actually worth adopting.
  • You need guidance on when FP helps and when it is better to keep code simple.

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, imperative is faster (no intermediate arrays)
function sumLarge(numbers: number[]): number {
  let sum = 0
  for (let i = 0; i < numbers.length; i++) {
    sum += numbers[i]
  }
  return sum
}

// fp-ts creates intermediate structures
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/${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/${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.
Câu hỏi thường gặp

Lập trình hàm là gì?

Đây là kiểu lập trình mà bạn xây dựng phần mềm bằng cách nghĩ về các hàm biến đổi dữ liệu, thay vì thay đổi trạng thái của mọi thứ.

Khi nào KHÔNG nên dùng lập trình hàm?

Hãy tránh khi mã đơn giản đã giải quyết được vấn đề (ví dụ kiểm tra null đơn giản), hoặc khi nhóm của bạn chưa quen với kiểu lập trình này.

Hướng dẫn này có dạy mọi thứ về lập trình hàm không?

Không. Hướng dẫn chỉ tập trung vào 20% khái niệm mang lại 80% kết quả, bỏ qua phần thuật ngữ hàn lâm.

Chi tiết

Mô tả gốc của tác giả

A practical, jargon-free guide to functional programming - the 80/20 approach that gets results without the academic overhead

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4645
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự