functional

Applies functional programming patterns with immutable data to TypeScript logic and transformations.

Updated May 18, 2024
One-click install
npx skills add https://github.com/joshhornby/dotfiles --skill functional-joshhornby
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: functional
Source: https://github.com/joshhornby/dotfiles/tree/main/.claude/skills/functional
Command: npx skills add https://github.com/joshhornby/dotfiles --skill functional-joshhornby

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mutation bugs, deeply nested conditionals, and unpredictable side effects make TypeScript code hard to test and reason about. This Skill provides concrete patterns for writing pure, composable functions with immutable data structures. ## Core Features & Use Cases - Immutability enforcement: Catalog of immutable alternatives to every common array and object mutation, plus readonly and ReadonlyArray<T> typing guidance. - Composition and refactoring: Worked examples for composing small functions into pipelines, flattening deep nesting with guard clauses, and isolating impure I/O at system boundaries. - Pragmatic scope: Covers Result types for error handling, options objects for parameter groups, and early returns, while explicitly avoiding heavy FP abstractions like monads or fp-ts. - Use Case: When fixing a bug where a shared array is mutated unexpectedly, load the immutability catalog to find the correct immutable alternative and apply readonly types so the compiler prevents recurrence. ## Quick Start Ask the AI to refactor a TypeScript function that mutates its arguments into a pure function using immutable data and early returns.

Frequently Asked Questions about functional

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I update an array immutably in TypeScript?

Use spread syntax and non-mutating methods instead of push, splice, or sort. For example, add items with [...items, newItem], remove by index with slice combinations, and sort with [...items].sort() to copy first.

How to fix mutation bugs caused by shared objects in JavaScript?

Return new objects with the spread operator instead of mutating arguments, and mark data structures with readonly properties and ReadonlyArray<T> so the TypeScript compiler rejects mutation attempts at compile time.

When should I use readonly vs ReadonlyArray in TypeScript?

Use readonly on object properties whose contract is immutable, and ReadonlyArray<T> for arrays callers must not mutate. Local encapsulated implementation state can stay mutable when it does not leak into the domain contract.

Should I use fp-ts or Ramda for functional programming in TypeScript?

This Skill recommends Functional Light principles: pure functions, immutable data, and composition without heavy libraries. Avoid monads, fp-ts, and Ramda unless the project explicitly requires them, since they add abstraction cost.

When should a function use an options object instead of positional parameters?

Use an options object when parameters form a meaningful group, several values share the same type, or optional arguments make ordering unclear. Keep simple positional APIs like add(a, b) positional when the order is obvious.

When is a Result type better than throwing exceptions?

Use a Result type when expected failures are part of the caller-facing contract and callers must handle both branches explicitly. Preserve existing exception or nullable-value conventions when they communicate the contract more clearly.