用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ranbot-ai/awesome-skills --skill fp-refactor命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | fp-refactor |
| description | Comprehensive guide for refactoring imperative TypeScript code to fp-ts functional patterns |
| category | Document Processing |
| source | antigravity |
| tags | ["typescript","node","api","ai","document","rag"] |
| url | https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/fp-refactor |
This skill provides comprehensive patterns and strategies for migrating existing imperative TypeScript code to fp-ts functional programming patterns.
try/catch, null checks, callbacks, DI, or loops into functional equivalents.Traditional try-catch blocks have several issues:
function parseJSON(input: string): unknown {
try {
return JSON.parse(input);
} catch (error) {
throw new Error(`Invalid JSON: ${error}`);
}
}
function validateUser(data: unknown): User {
try {
if (!data || typeof data !== 'object') {
throw new Error('Data must be an object');
}
const obj = data as Record<string, unknown>;
if (typeof obj.name !== 'string') {
throw new Error('Name is required');
}
if (typeof obj.age !== 'number') {
throw new Error('Age must be a number');
}
return { name: obj.name, : obj. };
} (error) {
error;
}
}
(): | {
{
data = (input);
user = (data);
user;
} (error) {
.(, error);
;
}
}
import * as E from 'fp-ts/Either';
import * as J from 'fp-ts/Json';
import { pipe } from 'fp-ts/function';
interface User {
name: string;
age: number;
}
// Use Json.parse which returns Either<Error, Json>
const parseJSON = (input: string): E.Either<Error, unknown> =>
pipe(
J.parse(input),
E.mapLeft((e) => new Error(`Invalid JSON: ${e}`))
);
// Validation returns Either, making errors explicit in types
const validateUser = (data: unknown): E.Either<Error, User> => {
if (!data || typeof data !== 'object') {
return E.left(new Error('Data must be an object'));
}
const obj = data as Record<string, >;
( obj. !== ) {
E.( ());
}
( obj. !== ) {
E.( ());
}
E.({ : obj., : obj. });
};
processUserInput = (: ): E.<, > =>
(
(input),
E.(validateUser)
);
(
(),
E.(
.(, error.),
.(, user)
)
);
T to Either<E, T> where E is your error typethrow new Error(...) to E.left(new Error(...))return value to E.right(value)pipe with E.flatMap to chain operationsasync function fetchUser(id: string): Promise<User> {
try {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const data = await response.json();
return validateUser(data);
} catch (error) {
throw new Error(`Failed to fetch user: ${error}`);
}
}
async function fetchUserPosts(userId: string): Promise<Post[]> {
try {
const response = await fetch(`/api/users/${userId}/posts`);
if (!response.ok) {