Files
cleveragents-core/.opencode/skills/programming-patterns/references/functional
freemo d9e5668cec fix(skills): comprehensive final audit pass for programming-patterns skill
Fixes and improvements from exhaustive audit:

Consistency fixes in SKILL.md:
- 'Pipe & Filter' → 'Pipe and Filter' (one stray '&' found and corrected)
- 'Singleton for factory instance' → clarified to 'register factory as
  singleton-scoped via DI container' (less misleading wording)
- Documentation Format section updated with note that SKILL.md itself is the
  authoritative source for related-pattern combinations

Coverage fix — Related Patterns sections:
- Added '## Related Patterns' to ALL 94 pattern files (was 0/94)
- Each section lists 3–6 related patterns with relationship descriptions
- Covers: why they're related, when to prefer one vs the other,
  and which are often confused

SOLID principles → Creational → Structural → Behavioral → Architectural →
Concurrency → Functional → Resilience → Data Access → Messaging →
Testing → Error Handling → Microservice — all 13 categories covered

Code verification:
- Python: 0 failures (all 85 testable blocks pass)
- Go: 0 failures (all 76 testable blocks pass)
- JavaScript: 0 failures (all 78 testable blocks pass)
- All 239 code blocks verified correct after edits

Final skill state:
- 108 files, 36,524 lines across 13 reference categories
- 94/94 pattern files have Related Patterns sections
- 2,815-line SKILL.md with 67 decision trees, 23 scenarios,
  0 broken references, 0 naming inconsistencies
2026-04-15 13:22:13 -04:00
..

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

  1. Prefer pure functions -- same input always produces same output, no side effects.
  2. Avoid mutation -- create new values instead of modifying existing ones.
  3. Compose small functions into larger transformations.
  4. Make illegal states unrepresentable using types (Monad pattern).
  5. Defer work until actually needed (Lazy Evaluation).