Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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 AbstractFactory returning families of products, or a class with clone() / 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/WeakMap cache + factory function
  • Replacing a State / Visitor / Composite class hierarchy with a discriminated union + exhaustive match function
  • 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 for loops with mutated accumulators that would read more honestly as reduce, Object.groupBy, or flatMap

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-
Полный SKILL.md на GitHub

Установить implementation-functional-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdmetadata.jsonreferences/_sections.mdreferences/cache-weakmap-over-flyweight.mdreferences/closure-as-command.mdreferences/create-factory-function-over-factory-classes.mdreferences/create-fluent-immutable-builder.mdreferences/create-module-scope-over-singleton.mdreferences/hof-lambda-as-strategy.mdreferences/match-tagged-union-over-state-visitor-composite.mdreferences/pipe-compose-over-decorator.mdreferences/pipe-pipeline-over-chain-of-responsibility.mdreferences/place-module-scope-pure-transformers.mdreferences/signal-event-emitter-over-mediator-and-observer.mdreferences/stream-flatmap-over-nested-loops.mdreferences/stream-lazy-iteration-for-large-or-infinite.mdreferences/stream-prefer-single-pass-over-chained-passes.mdreferences/stream-reduce-over-imperative-accumulation.mdreferences/wrap-function-over-adapter-and-facade.mdreferences/wrap-proxy-native-or-hof.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить implementation-functional-patterns с