functional-patterns
Refactor imperative loops into functional data pipelines using map, filter, reduce, sort, and slice.
Skill by nitrictech
Chalk Labs
Need help deploying functional-patterns?
Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/nitrictech-functional-patterns
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: data
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/functional-patterns
Tools it pre-approves 5
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
Read,Edit,Grep,Glob,Bash
What's inside
- Skill name
functional-patterns- Description
- Refactor imperative loops into functional data pipelines using map, filter, reduce, sort, and slice. Replace procedural data processing with declarative transformations.
- License
- MIT
- Allowed tools
- Read,, Edit,, Grep,, Glob,, Bash
- Instructions
- 261 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves any shell command
Files (1)
- SKILL.md
SKILL.md (first lines)
# Functional Patterns
When invoked, review the specified code for imperative loops that transform, filter, or aggregate data. Refactor into functional data pipelines using the language's built-in higher-order functions. The goal is declarative code that clearly states *what* happens to the data, with the *how* handled by well-known primitives.
If the user has not specified a scope (file or directory), ask them which file or directory to focus on before proceeding.
## Core Rules
1. **Use `filter` to select elements matching a condition.** Replaces loops with `if` + `append`. The predicate function declares which elements to keep.
2. **Use `map` to transform each element.** Replaces loops that build a new list of transformed items. The mapper function declares what each element becomes.
3. **Use `reduce`/`fold` to aggregate a collection into a single value.** Replaces loops with an accumulator variable. The reducer function declares how elements combine.
4. **Use `sort` with a comparator function.** Replaces manual sorting loops or insertion-based ordering. The comparator declares the ordering criterion.
5. **Use `slice`/`take` to limit results.** Replaces counter-based early exits from loops.
6. **Chain operations into data pipelines.** Order the chain logically:
- **Filter first** -- reduce data volume early to avoid unnecessary work.
- **Map second** -- transform remaining elements into the shape you need.
- **Sort third** -- order the transformed results.
- **Slice last** -- take only what you need from the sorted results.
7. **Use lambda/arrow functions for short predicates and transformers.** A one-line lambda is more readable inline than a named function in a different location. Extract to a named function only when the logic is complex enough to benefit from a descriptive name or when it is reused.
8. **Do not force functional style where it does not fit.** Side-effectful operations -- database writes, API calls, file I/O, sending notifications -- should remain imperative. Functional pipelines are for data transformation, not orchestration. If a loop's body performs side effects on each iteration, it is not a candidate for `map`.
9. **Watch for performance implications.** Chaining `filter`, `map`, and `sort` creates multiple passes over the data. For small-to-medium collections (typical business logic), this is negligible. For very large datasets or hot paths, a single-pass loop may be warranted -- add a comment explaining why the imperative form is intentional.
10. **Prefer pure functions.** Functions in the pipeline should take inputs and return outputs without modifying external state. This makes each step independently understandable and testable.
## Language-Specific Idioms
Adapt to the language of the user's codebase:
- **JavaScript/TypeScript:** Method chaining on arrays -- `.filter().map().sort().slice()`. Use arrow functions.
- **Python:** List comprehensions for simple filter+map (`[x.name for x in items if x.active]`). Use `sorted()` with `key=`. Use `itertools` for advanced patterns. Generator expressions for lazy evaluation.
- **Java:** Streams API -- `stream().filter().map().sorted().limit().collect()`.
- **C#:** LINQ -- `.Where().Select().OrderBy().Take()`.
- **Rust:** Iterator chains -- `.iter().filter().map().sorted().take().collect()`.
- **Go:** No built-in higher-order functions on slices (pre-generics). Use `slices` package or simple loops. Do not force functional style in Go -- idiomatic Go uses explicit loops.
## Procedure
1. **Identify candidate loops.** Look for `for`/`while` loops that:
- Build up a result list by appending conditionally (→ filter).
- Build a new list by transforming each element (→ map).
- Compute a single aggregate value from a collection (→ reduce).
- Sort elements by comparison (→ sort).
- Stop after N results (→ slice/take).
- Combine two or more of the above.
2. **Classify each loop by purpose.** A single loop often combines filtering and mapping. Decompose it into its constituent operations.
3. **Rewrite using higher-order functions.** Chain them in pipeline order. Use the language's idiomatic syntax.
4. **Preserve behavior.** The refactored code must produce identical results. Pay attention to:
- Order of elements (filter preserves order, sort changes it).
- Handling of empty collections.
- Side effects in the original loop body -- if present, the loop is not a candidate for pure functional refactoring.
5. **Present changes** with a brief explanation of what each pipeline step does.
---
## Examples
### Example A: Filter + Map Pipeline
An imperative loop that selects employees and extracts their names:
**Before:**
```typescript
function getSeniorEngineerNames(employees: Employee[]): string[] {
const result: string[] = [];
for (let i = 0; i < employees.length; i++) {
const emp = employees[i];
if (emp.department === "Engineering") {
if (emp.yearsOfService > 5) {
result.push(emp.firstName + " " + emp.lastName);
}
}
}
return result;
}
```
The loop mixes three concerns: iterating, filtering, and transforming. The nested `if` statements obscure the intent.
**After:**
```typescript
function getSeniorEngineerNames(employees: Employee[]): string[] {
return employees
.filter(emp => emp.department === "Engineering" && emp.yearsOfService > 5)
.map(emp => `${emp.firstName} ${emp.lastName}`);
}
```
The pipeline reads as a declaration: "from all employees, keep the senior engineers, then extract their full names." Each step does one thing. No index variable, no temporary array, no nested conditions.
---
### Example B: Reduce for Aggregation
A loop that computes a running balance from a list of transactions:
**Before:**
```python
def calculate_balance(transactions):
balance = 0
overdraft_count = 0
for txn in transactions:From nitrictech/skills, MIT.
More from nitrictech/skills
- 0.494score
self-document
nitrictech
Improve readability by fixing names and eliminating unnecessary comments.
SkillCFreshness: C★ 1Claude Code +9 - 0.494score
flatten
nitrictech
Find and fix deeply nested code using extraction (pull logic into functions) and inversion (guard clauses, early returns).
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
review-security
nitrictech
Audit an entire source tree for security vulnerabilities, validating findings against framework and library documentation to avoid false positives.
SkillCFreshness: C★ 1Claude Code - 0.492score
senior-review
nitrictech
Review a code changes, PR, etc.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
implement
nitrictech
Implement a code change, typically a PR, as specified by the user.
SkillCFreshness: C★ 1Claude Code +9 - 0.429score
dependency-injection
nitrictech
Refactor code to use dependency injection.
SkillDFreshness: D★ 1Claude Code +9 - 0.429score
simplify-abstractions
nitrictech
Evaluate abstractions and inheritance for over-coupling.
SkillDFreshness: D★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Apr 13, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/nitrictech/skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from nitrictech
- 0.494score
self-document
nitrictech
Improve readability by fixing names and eliminating unnecessary comments.
SkillCFreshness: C★ 1Claude Code +9 - 0.494score
flatten
nitrictech
Find and fix deeply nested code using extraction (pull logic into functions) and inversion (guard clauses, early returns).
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
review-security
nitrictech
Audit an entire source tree for security vulnerabilities, validating findings against framework and library documentation to avoid false positives.
SkillCFreshness: C★ 1Claude Code - 0.492score
senior-review
nitrictech
Review a code changes, PR, etc.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
implement
nitrictech
Implement a code change, typically a PR, as specified by the user.
SkillCFreshness: C★ 1Claude Code +9 - 0.429score
dependency-injection
nitrictech
Refactor code to use dependency injection.
SkillDFreshness: D★ 1Claude Code +9
Done for you
Rather not set it up yourself?
Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.
See how we build AI agents →Read the case studies
Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.
- launches shipped
- 50+
- launches shipped
- media placements
- 500+
- media placements
- founders on every account
- 2
- founders on every account
Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block
Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.
Get functional-patterns running in your business
Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.
Cite this page
functional-patterns skill. Agent Mart. https://agentmart.dev/skills/nitrictech-functional-patterns (last updated 2026-10-24)