fp-refactor_skill

This skill helps you migrate imperative TypeScript code to fp-ts patterns, enabling explicit errors, safe optional handling, and functional composition.

2

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill whatiskadudoing/fp-ts-skills --skill fp-refactor

  • SKILL.md44.4 KB

Overview

This skill is a practical guide for refactoring imperative TypeScript into fp-ts functional patterns. It focuses on concrete migrations—try/catch to Either/TaskEither, null checks to Option, callbacks to Task, class DI to Reader, and Promise/loop refactors—so you get safer, composable code without academic jargon.

How this skill works

The guide inspects common imperative idioms and provides step-by-step patterns and code transforms using fp-ts primitives (Either, TaskEither, Option, Task, Reader, Array helpers). It shows how to change return types, replace throws/nulls/callbacks, and compose operations with pipe and flatMap. It also includes helper utilities and migration strategies for gradual adoption.

When to use it

  • Replacing nested try-catch and thrown errors with explicit error types
  • Making nullable or optional data explicit and composable
  • Converting Node-style callbacks and Promise chains into composable tasks
  • Refactoring class-based dependency injection to pure Readers for testability
  • Rewriting imperative loops and finds into fp-ts Array/Option pipelines

Best practices

  • Start at boundaries: convert incoming nullable values and I/O to Option/Either/TaskEither
  • Define small error types and propagate them explicitly rather than throwing generic Errors
  • Prefer pipe + flatMap/map for composition so errors and None propagate automatically
  • Provide thin adapters at non-fp boundaries (getOrElse, match, toNullable) instead of spreading conversions
  • Migrate incrementally: wrap existing functions with tryCatch helpers and progressively replace call sites

Example use cases

  • Turn JSON.parse + validate + nested try-catch into Either pipelines with explicit error types
  • Wrap fetch and multiple network calls into TaskEither with automatic error propagation and sequencing
  • Replace deep optional property checks in config objects with nested Option combinators and getOrElse fallbacks
  • Convert Node callback-based file operations to Task/TaskEither and compose batch processing without callback hell
  • Replace imperative array.find + null checks with fp-ts Array.findFirst and Option.map chains

FAQ

No. Start at boundaries and critical modules. Use tryCatch adapters and Option.fromNullable wrappers to incrementally adopt fp-ts patterns.

How do I handle external libraries that return null or throw?

Wrap external calls with tryCatch (sync/async) and fromNullable at the boundary, converting their results into Either/TaskEither/Option before spreading into your code.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
fp-refactor skill by whatiskadudoing/fp-ts-skills | VeilStrat