implementation-functional-patterns
БесплатноБез исполняемых скриптовНе проверенTypeScript's functional answers to the 22 Gang of Four classes — factory functions (Factory Method, Abstract Factory, Prototype, Memento), module-scope…
от pproenca★ 231 звезда на GitHubОб этом скилле
TypeScript Functional Patterns
Implementation reference for the functional shapes that supersede the Gang of Four catalog in idiomatic TypeScript. Sibling to implementation-design-patterns: read that one when the answer is a class, this one when the answer is a function, a tagged union, or a small data structure.
TypeScript has first-class functions, discriminated unions, structural typing, and zero ceremony around closures. That means the 22 GoF patterns — written in the catalog as class hierarchies because the source material targets Java/C# — collapse to far fewer functional shapes in real TS code. Several patterns share a functional answer: tagged unions cover State, Visitor, and Composite; factory functions cover Factory Method, Abstract Factory, Prototype, and Memento; event emitters cover Mediator and Observer; wrapper functions cover Adapter and Facade. This skill names those collapses, the placement rules they imply, and the performance trade-offs.
When to Apply
- Refactoring a Factory class hierarchy, an
AbstractFactoryreturning families of products, or a class withclone()/ Memento save-restore - Refactoring a Singleton class with
private constructor+static getInstance - Refactoring a mutable Builder class for a configuration object with many optional fields
- Refactoring a Strategy / Template Method / Bridge class hierarchy where variation is a single method
- Replacing a Chain of Responsibility class chain or Decorator wrapper-class stack
- Replacing a custom Iterator class with stream methods, generators, or lazy iterator helpers
- Replacing a Command class with a closure stored in a queue (when undo/serialization is not required)
- Replacing an Adapter / Facade class that exists only to forward calls or hide subsystem orchestration
- Replacing a Proxy class with native JS
Proxy(for transparent interception) or an HOF wrapper (for selective wrapping) - Replacing a Flyweight factory class with a
Map/WeakMapcache + factory function - Replacing a State / Visitor / Composite class hierarchy with a discriminated union + exhaustive
matchfunction - Replacing a Mediator / Observer class with an event emitter or reactive signal
- Reviewing TSX where lambdas appear inline in JSX, hook deps, or
memo'd child props — placement controls identity - Recognizing imperative
forloops with mutated accumulators that would read more honestly asreduce,Object.groupBy, orflatMap
Rule Categories
| # | Category | Impact | Rules | Theme |
|---|---|---|---|---|
| 1 | Creational alternatives (create) |
HIGH | 3 | Factory functions, module-scope singletons, fluent immutable builders |
| 2 | Higher-order functions (hof) |
HIGH | 1 | Pass a function instead of a class |
| 3 | Pipelines & composition (pipe) |
HIGH | 2 | Compose small functions: pipe (data flow), compose (wrapper layering) |
| 4 | Stream methods (stream) |
HIGH | 4 | map/filter/flatMap/reduce, lazy iteration, single-pass chains |
| 5 | Wrappers (wrap) |
HIGH | 2 | Wrapper functions for Adapter/Facade; native Proxy or HOF for Proxy |
| 6 | Caching & sharing (cache) |
HIGH | 1 | Map/WeakMap + factory function over Flyweight class |
| 7 | Pattern matching (match) |
HIGH | 1 | Discriminated unions + exhaustive match for State/Visitor/Composite |
| 8 | Signals & event emitters (signal) |
HIGH | 1 | Event emitter / signal for Mediator/Observer |
| 9 | Placement & identity (place) |
HIGH | 1 | Where the lambda lives controls behavior |
| 10 | Closures as data (closure) |
MEDIUM | 1 | Functions that carry their state |
17 rules across 10 categories, covering all 22 GoF patterns (some patterns share a functional answer — see the GoF → Functional Map below).
GoF → Functional Map
The full mapping from each Gang of Four pattern to its functional answer in idiomatic TS. Read this table to find the rule for a specific pattern; read the categories above to find rules by functional technique.
| GoF Group | GoF Pattern | Functional Equivalent | Rule |
|---|---|---|---|
| Creational | Factory Method | Function returning tagged object | create-factory-function-over-factory-classes |
| Abstract Factory | Function returning record of constructors | covered by factory-function rule | |
| Builder | Object literal + Partial<T>, or fluent immutable |
create-fluent-immutable-builder |
|
| Prototype | structuredClone / spread / Immer produce |
covered by factory-function rule | |
| Singleton | Module-scope const, lazy ??= memo |
create-module-scope-over-singleton |
|
| Structural | Adapter | Wrapper function translating shape | [`wrap-function-over-adapter-and- |
Установить implementation-functional-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл implementation-functional-patterns?
TypeScript's functional answers to the 22 Gang of Four classes — factory functions (Factory Method, Abstract Factory, Prototype, Memento), module-scope singletons, fluent immutable builders, wrapper functions (Adapter, Facade), native Proxy, WeakMap caches (Flyweight), discriminated unions with exhaustive match (State, Visitor, Composite), event emitters and signals (Mediator, Observer), pipelines and composition (CoR, Decorator), stream methods (Iterator), closures-as-commands, higher-order strategies, lambda placement. Use when reviewing TypeScript that has a class-shaped problem the GoF catalog solves with a hierarchy but where idiomatic TS reaches for a function, a tagged union, or a data structure. Each rule names the GoF pattern(s) it replaces and when the class form still wins. Trigger on "factory class", "singleton getInstance", "state machine class", "observer pattern", "AST visitor", "where do I put this lambda". Sibling to implementation-design-patterns.
Как установить скилл implementation-functional-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл implementation-functional-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic