typescript-functional
TypeScript functional programming. Use for pure functions, immutability, composition. Favors ternaries, switch, map/filter/reduce over imperative code. Concise, declarative patterns.
When & Why to Use This Skill
This Claude skill optimizes TypeScript development by implementing functional programming paradigms. It focuses on pure functions, immutability, and declarative patterns to enhance code maintainability, reduce side effects, and improve overall software reliability through concise and predictable logic.
Use Cases
- Refactoring legacy imperative 'for' loops into clean, declarative 'map', 'filter', and 'reduce' chains for better readability.
- Ensuring data integrity in complex state management by enforcing immutability and preventing direct object mutations.
- Improving unit testability by decomposing complex logic into small, single-purpose pure functions and functional compositions.
- Standardizing conditional logic across a codebase using functional expressions like ternaries and exhaustive switch statements instead of nested if-else blocks.
| name | typescript-functional |
|---|---|
| # IMPORTANT | Keep description on ONE line for Claude Code compatibility |
| description | TypeScript functional programming. Use for pure functions, immutability, composition. Favors ternaries, switch, map/filter/reduce over imperative code. Concise, declarative patterns. |
TypeScript Functional Programming
Quick Start
Core principles: Pure functions | Immutability | Composition | Higher-order functions | Declarative over imperative
Prefer: ? : over if | switch over if/else chains |
map/filter/reduce over loops | const over let | Expressions over statements
Example
// ❌ Imperative
function processUsers(users: User[]): string[] {
let result = [];
for (let i = 0; i < users.length; i++) {
if (users[i].age >= 18) {
result.push(users[i].name.toUpperCase());
}
}
return result;
}
// ✅ Functional
const processUsers = (users: User[]): string[] =>
users
.filter(user => user.age >= 18)
.map(user => user.name.toUpperCase());
// ✅ Ternary over if
const getStatus = (age: number): string =>
age >= 18 ? 'adult' : 'minor';
// ✅ Switch for multiple conditions
const getDiscount = (tier: Tier): number => {
switch (tier) {
case 'gold': return 0.2;
case 'silver': return 0.1;
case 'bronze': return 0.05;
default: return 0;
}
};
Reference Files
Check these before suggesting code:
- references/pure-functions.md - Pure function patterns and side effect handling
- references/array-methods.md - map, filter, reduce, and functional iteration
- references/composition.md - Function composition and piping patterns
- references/immutability.md - Immutable data structures and updates
- references/control-flow.md - Ternaries, switch, and functional conditionals
Notes
- Avoid mutations: Use spread operators and array methods
- No
letunless absolutely necessary (preferconst) - Functions should be small, single-purpose, composable
- Prefer function expressions over statements
- Use type inference when possible, explicit types when needed
- Early returns are acceptable for guard clauses
- Last verified: 2025-12-03