fp-pipe-ref
它能做什么
这些工具可以帮你组织代码中的一系列操作。`pipe` 会一次性把一系列转换依次作用于一个值。`flow` 会创建一个新函数,把多个转换组合起来,供以后使用。
适用场景
- ✓当你需要对数据依次进行多个处理步骤时。
- ✓当你想创建一个可以反复使用、按特定方式处理数据的函数时。
- ✓当你使用的库会把函数组织成一系列操作时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-pipe-ref/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我怎样把一个字符串去掉多余空格、转换成大写,然后拆分成单词?”
每周 5 个新技能,1 分钟读完。
工作原理
`pipe` 函数接收一个初始值,然后让它依次经过一系列函数处理。`flow` 函数会把多个函数组合成一个新函数,之后就可以用同样的方式处理不同的值。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
pipe & flow Quick Reference
pipe - Transform a Value
import { pipe } from 'fp-ts/function'
// pipe(startValue, fn1, fn2, fn3)
// = fn3(fn2(fn1(startValue)))
const result = pipe(
' hello world ',
s => s.trim(),
s => s.toUpperCase(),
s => s.split(' ')
)
// ['HELLO', 'WORLD']
flow - Create Reusable Pipeline
import { flow } from 'fp-ts/function'
// flow(fn1, fn2, fn3) returns a new function
const process = flow(
(s: string) => s.trim(),
s => s.toUpperCase(),
s => s.split(' ')
)
process(' hello world ') // ['HELLO', 'WORLD']
process(' foo bar ') // ['FOO', 'BAR']
When to Use
| Use | When |
|---|---|
pipe |
Transform a specific value now |
flow |
Create reusable transformation |
With fp-ts Types
import * as O from 'fp-ts/Option'
import * as A from 'fp-ts/Array'
// Option chain
pipe(
O.fromNullable(user),
O.flatMap(u => O.fromNullable(u.email)),
O.getOrElse(() => 'no email')
)
// Array chain
pipe(
users,
A.filter(u => u.active),
A.map(u => u.name)
)
Common Pattern
// Data last enables partial application
const getActiveNames = flow(
A.filter((u: User) => u.active),
A.map(u => u.name)
)
// Reuse anywhere
getActiveNames(users1)
getActiveNames(users2)
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.
常见问题
`pipe` 和 `flow` 有什么区别?
`pipe` 用于立即转换某个特定的值,按顺序应用函数。`flow` 用于创建一个组合了多个转换的新函数,之后可以多次使用。
`pipe` 和 `flow` 通常用来做什么?
它们可以帮助串联或组合函数,让代码更易读、更有条理,尤其是在有多个处理步骤的时候。
这两个工具可以用于任何数据类型吗?
可以,只要 `pipe` 或 `flow` 中使用的函数能够兼容在它们之间传递的数据类型即可。
详情
作者的原始描述
Quick reference for pipe and flow. Use when user needs to chain functions, compose operations, or build data pipelines in fp-ts.
热度
- GitHub 星标
- 48k
- 排名
- #4644
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。