whatiskadudoing/fp-ts-skills/fp-refactor
Trust tier 1
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Comprehensive guide for refactoring imperative TypeScript code to fp-ts functional patterns
Install
npx vskill@latest install whatiskadudoing/fp-ts-skills/fp-refactorSKILL.md
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.
Table of Contents
- Converting try-catch to Either/TaskEither
- Converting null checks to Option
- Converting callbacks to Task
- Converting class-based DI to Reader
- Converting imperative loops to functional operations
- Migrating Promise chains to TaskEither
- Common Pitfalls
- Gradual Adoption Strategies
- When NOT to Refactor
1. Converting try-catch to Either/TaskEither
The Problem with try-catch
Traditional try-catch blocks have several issues:
- Error handling is implicit and easy to forget
- The type system doesn't track which functions can throw
- Control flow is non-linear and harder to reason about
- Composing multiple fallible operations is verbose
Pattern: Synchronous try-catch to Either
Before (Imperative)
After (fp-ts Either)
Step-by-Step Refactoring Guide
- Identify the error type: Determine what errors can occur and create appropriate error types
- Change return type: From
TtoEither<E, T>whereEis your error type - Replace throw statements: Convert
throw new Error(...)toE.left(new Error(...)) - Replace return statements: Convert
return valuetoE.right(value) - Remove try-catch blocks: They're no longer needed
- Update callers: Use
pipewithE.flatMapto chain operations
Pattern: Async try-catch to TaskEither
Before (Imperative)
After (fp-ts TaskEither)
Helper: tryCatch Utility
Create a reusable wrapper for functions that might throw:
2. Converting null checks to Option
The Problem with null/undefined
- TypeScript's strict null checks help, but null still spreads through code
- Chained property access requires verbose null guards
- The distinction between "missing" and "present but null" is unclear
- Easy to forget null checks leading to runtime errors
Pattern: Simple null checks to Option
Before (Imperative)
After (fp-ts Option)
Pattern: Array find operations
Before (Imperative)
After (fp-ts Option)
Step-by-Step Refactoring Guide
- Identify nullable values: Find all
T | null,T | undefined, or optional properties - Wrap with fromNullable: Convert nullable values to Option at system boundaries
- Change return types: From
T | nulltoOption<T> - Replace null checks: Use
O.map,O.flatMap,O.filterinstead of if statements - Handle at boundaries: Use
O.getOrElse,O.match, orO.toNullablewhen interfacing with non-fp code
Converting Between Option and Either
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 46 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/fp-refactor/SKILL.md
Popularity
- Repository stars
- 4
- Repository forks
- 2
- 7-day trend score
- 8
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 23 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/whatiskadudoing/fp-ts-skills/fp-refactor)