Individual skill
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.
skills/.curated/implementation-functional-patterns/SKILL.md
Source commit cf93c57cac89d6fc3e4194686000411567f5caf3
What was checked
- Matches the observed repository HEAD
- Yes
- Scanner rules are current
- No
- Repository scan complete
- No
- Skill scan complete
- No
- Observed behavior
- Not checked yet
- Last checked
- Nov 5, 2026
These are observations at the recorded commit, not a guarantee of safety. Review the source before running it.
Install this skill
Choose an agent in your Stack or copy a command below. Commands fetch the pinned commit and copy only this skill directory. Existing destinations are refused. Copying a command does not install anything.
An install command is unavailable: current rules, complete repository and skill scans, an eligible behavior level and a permitted license are required.
Repository context
- Repository stars (not skill ratings)
- 222
- Repository last updated
- Aug 15, 2026
- License
- MIT
Observed agent integration: codex
Files and excerpt
File metadata and permitted, redacted excerpts come from the recorded scan. Source links are pinned to that commit.
Browse files
AGENTS.mddoc · 5,362 bytesSKILL.mdcore · 17,674 bytesSKILL.mdcore · 17,674 bytesSKILL.mdcore · 17,674 bytesmetadata.jsonasset · 1,268 bytesreferences/_sections.mddoc · 5,256 bytesreferences/cache-weakmap-over-flyweight.mddoc · 7,020 bytesreferences/closure-as-command.mddoc · 6,041 bytesreferences/create-factory-function-over-factory-classes.mddoc · 8,594 bytesreferences/create-fluent-immutable-builder.mddoc · 8,119 bytesreferences/create-module-scope-over-singleton.mddoc · 7,166 bytesreferences/hof-lambda-as-strategy.mddoc · 5,288 bytesreferences/match-tagged-union-over-state-visitor-composite.mddoc · 7,934 bytesreferences/pipe-compose-over-decorator.mddoc · 9,581 bytesreferences/pipe-pipeline-over-chain-of-responsibility.mddoc · 5,940 bytesreferences/place-module-scope-pure-transformers.mddoc · 6,856 bytesreferences/signal-event-emitter-over-mediator-and-observer.mddoc · 9,195 bytesreferences/stream-flatmap-over-nested-loops.mddoc · 5,040 bytesreferences/stream-lazy-iteration-for-large-or-infinite.mddoc · 5,774 bytesreferences/stream-prefer-single-pass-over-chained-passes.mddoc · 6,282 bytesreferences/stream-reduce-over-imperative-accumulation.mddoc · 5,565 bytesreferences/wrap-function-over-adapter-and-facade.mddoc · 8,097 bytesreferences/wrap-proxy-native-or-hof.mddoc · 8,333 bytes
Read excerpt
# TypeScript Functional Patterns
Implementation reference for the functional shapes that supersede the Gang of Four catalog in idiomatic TypeScript. Sibling to [`implementation-design-patterns`](../implementation-design-patterns/SKILL.md): 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