fp-refactor
Comprehensive guide for refactoring imperative TypeScript code to fp-ts functional patterns
npx skills add sickn33/agentic-awesome-skills --skill fp-refactor --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
This skill provides comprehensive patterns and strategies for migrating existing imperative TypeScript code to fp-ts functional programming patterns.
How it works
- When refactoring, it suggests converting try/catch blocks to Either or TaskEither, including synchronous and asynchronous examples, and provides a step-by-step refactoring guide:
- Identify the error type
- Change return type to Either<E, T>
- Replace throw statements with E.left(...)
- Replace returns with E.right(...)
- Remove try-catch blocks
- Update callers using pipe with E.flatMap
- It shows converting null/undefined checks to Option, including wrapping nullable values with fromNullable, changing return types to Option, and using O.map/O.flatMap, with explicit boundary handling via getOrElse or match.
- It covers converting callbacks to Task, including Node-style callbacks to Task, and wrapping fs/promises in TaskEither with examples for reading and writing files, and composing multiple files.
- It includes patterns for converting class-based DI to Reader, and converting imperative loops to functional operations, though the provided excerpt focuses on the above three areas.
- It provides concrete code patterns: functions like parseJSON to Either, fetchUser to TaskEither, getDatabaseUrl to Option, findUserById to Option, readFile/writeFile to TaskEither, and multi-file processing via traverse.
When to use it
- You are refactoring an existing imperative TypeScript codebase toward fp-ts patterns.
- The task involves converting try/catch, null checks, callbacks, DI, or loops into functional equivalents.
- You need migration guidance and tradeoffs, not just isolated fp-ts examples.
What it can touch
- The skill references and demonstrates touchpoints with:
- fp-ts/Either, fp-ts/TaskEither, fp-ts/Option
- pipe from fp-ts/function
- Specific utilities: TE.tryCatch, TE.flatMap, TE.map, E.left, E.right, O.fromNullable, O.map, O.flatMap, O.match, A.findFirst, A.traverse
- File system APIs: fs.readFile, fs.writeFile (demonstrated via fs/promises in examples)
Caveats
- Declared risk: critical
- The skill provides patterns and examples; outcomes depend on correct application to actual codebases
- It emphasizes not to speculate beyond the coded patterns and to follow the step-by-step guides shown for refactoring
# Refactoring Imperative Code to fp-ts This skill provides comprehensive patterns and strategies for migrating existing imperative TypeScript code to fp-ts functional programming patterns. ## When to Use - You are refactoring an existing imperative TypeScript codebase toward fp-ts patterns. - The task involves converting `try/catch`, null checks, callbacks, DI, or loops into functional equivalents. - You need migration guidance and tradeoffs, not just isolated fp-ts examples. ## Table of Contents 1. [Converting try-catch to Either/TaskEither](#1-converting-try-catch-to-eithertaskeither) 2. [Converting null checks to Option](#2-converting-null-checks-to-option) 3. [Converting callbacks to Task](#3-converting-callbacks-to-task) 4. [Converting class-based DI to Reader](#4-converting-class-based-di-to-reader) 5. [Converting imperative loops to functional operations](#5-converting-imperative-loops-to-functional-operations) 6. [Migrating Promise chains to TaskEither](#6-migrating-promise-chains-to-taskeither) 7. [Common Pitfalls](#7-common-pitfalls) 8. [Gradual Adoption Strategies](#8-gradual-adoption-strategies) 9. [When NOT to Refactor](#9-when-not-to-refactor) --- ## 1. Converting try
- When to Use
- Table of Contents
- 1. Converting try-catch to Either/TaskEither
- The Problem with try-catch
- Pattern: Synchronous try-catch to Either
- Step-by-Step Refactoring Guide
- Pattern: Async try-catch to TaskEither
- Helper: tryCatch Utility
- 2. Converting null checks to Option
- The Problem with null/undefined
- Pattern: Simple null checks to Option
- Pattern: Array find operations
- Converting Between Option and Either
- 3. Converting callbacks to Task
What does the fp-refactor skill do?
Comprehensive guide for refactoring imperative TypeScript code to fp-ts functional patterns
How do I install it?
Run `npx skills add sickn33/agentic-awesome-skills --skill fp-refactor --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From sickn33/agentic-awesome-skills, a repository with 44,414 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.