functional-patterns

Applies functional programming principles to JavaScript and TypeScript code.

1|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/pnewsam/skills --skill functional-patterns-pnewsam
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: functional-patterns
Source: https://github.com/pnewsam/skills/tree/main/archive/functional-patterns
Command: npx skills add https://github.com/pnewsam/skills --skill functional-patterns-pnewsam

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? JavaScript and TypeScript codebases often accumulate bugs from mutable state, hidden side effects, and imperative control flow that is hard to test and review. This Skill provides a concrete set of functional programming principles so code is written and reviewed with immutability, pure functions, and composition in mind. ## Core Features & Use Cases - Immutability guidance: Enforces non-mutating updates using spread syntax, as const, readonly modifiers, and Immer for deeply nested structures. - Pure function and side-effect boundaries: Shows how to isolate side effects into thin wrapper functions while keeping core computation pure and testable. - Declarative transformations: Replaces imperative loops, switch statements, and if/else assignments with array method chains, lookup tables, ternaries, and guard clauses. - Use Case: When reviewing a pull request that mutates shared objects inside a data pipeline, apply these principles to rewrite the transformations as pure, chained array operations with explicit side-effect boundaries. ## Quick Start Review this TypeScript data transformation module and rewrite it following functional programming principles with immutable updates and pure functions.

Frequently Asked Questions about functional-patterns

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

FAQPage Schema
How do I write immutable updates in TypeScript?▼

Use spread syntax to create new objects instead of mutating in place, such as `{ ...user, name: newName }`. For nesting deeper than two levels, use Immer's `produce` function, and mark immutable data with `as const` or `readonly` modifiers.

How to refactor imperative loops into functional JavaScript?▼

Replace `for` loops with declarative array methods like `map`, `filter`, `find`, and `flatMap` that state intent directly. Chain the methods instead of creating intermediate variables, and reserve `reduce` for accumulating into a different shape like an object or Map.

When should I use classes versus functions in TypeScript?▼

Prefer exported functions and module-level composition for most logic, since they avoid hidden state and are easier to test. Use classes only when you genuinely need encapsulated mutable state with a lifecycle, such as database connections or WebSocket managers.

Should I use reduce or filter and map for array transformations?▼

Prefer `filter` and `map` chains when selecting and transforming elements, since the intent is self-documenting. Use `reduce` only when accumulating a sequence into a genuinely different shape like a grouped object, Map, or Set.

What is the difference between nullish coalescing and logical OR in JavaScript?▼

The `??` operator only replaces `null` and `undefined`, while `||` replaces all falsy values including `0`, empty strings, and `false`. Use `??` when falsy values are legitimate data, and combine it with optional chaining (`?.`) for safe nested access.