跳到正文
Skillpedia
通用编程48k · #4644

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-pipe-ref/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4644
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能