98680825a7
Adds a comprehensive opencode skill under .opencode/skills/programming-patterns/
covering 90+ design, architectural, concurrency, and functional patterns.
- 108 files, 33,500+ lines across 13 reference categories
- Every pattern: pseudocode + tested Python + Go + JavaScript implementations
- All 239 code blocks verified passing (85 Python, 76 Go, 78 JS)
- 1,569-line SKILL.md with:
- Master decision tree (all 14 categories with multi-pattern suggestions)
- 34 situation-specific decision trees covering every programming scenario
(new feature, refactoring, REST API, CLI, data pipeline, rule engine,
external integration, performance, memory, notifications, plugins,
caching, events, auth, reporting, vendor lock-in, domain model,
business rules, observability, file I/O, scheduling, testability,
third-party libs, concurrency, complex domain interactions)
- 12 compound pattern-combination scenarios with full architecture maps
(e-commerce checkout, REST endpoint, background jobs, real-time dashboard,
microservice resilience, ML pipeline, text editor, legacy migration,
multi-tenant SaaS, document approval, financial transactions, chat)
- 'When Am I Allowed to Skip Patterns?' mandate table (answer: never)
- Quick pattern lookup tables for all 90+ patterns
- Complete reference index
1.8 KiB
1.8 KiB
Functional Patterns
Overview
Functional patterns leverage concepts from functional programming to write code that is more predictable, composable, and testable. These patterns emphasize immutability, pure functions, and declarative data transformations.
Patterns in This Category
| Pattern | Purpose | Key Mechanism |
|---|---|---|
| Higher-Order Functions | Pass and return functions as values | map, filter, reduce |
| Monad | Chain operations with context (errors, nulls) | Maybe, Result types |
| Immutability | Prevent state mutation after creation | Frozen / read-only objects |
| Currying | Transform multi-arg functions into chains | Partial application |
| Memoization | Cache function results by inputs | Lookup table / decorator |
| Pattern Matching | Destructure and branch on data shape | match/case, type switch |
| Lazy Evaluation | Defer computation until value is needed | Generators, thunks |
When to Use Functional Patterns
- Data pipelines: Higher-Order Functions, Lazy Evaluation
- Error handling without exceptions: Monad (Result/Maybe)
- Concurrent / parallel code: Immutability (no shared mutable state)
- Configuration and DSLs: Currying
- Performance optimization: Memoization, Lazy Evaluation
- Complex conditional logic: Pattern Matching
General Principles
- Prefer pure functions -- same input always produces same output, no side effects.
- Avoid mutation -- create new values instead of modifying existing ones.
- Compose small functions into larger transformations.
- Make illegal states unrepresentable using types (Monad pattern).
- Defer work until actually needed (Lazy Evaluation).