Refactor Nested Procedural Code into Pure Pipelines
Transforms complex, deeply nested imperative code into clean, testable pure functions organized as a sequential data pipeline.
Agent prompt for ChatGPT and Claude
Prompt
mkdir -p .agents/skills/refactor-nested-procedural-code-into-pure-pipelines && curl -sL "https://prompts-gpt.com/prompts/refactor-nested-procedural-code-into-pure-pipelines/raw" -o .agents/skills/refactor-nested-procedural-code-into-pure-pipelines/SKILL.md---
name: refactor-nested-procedural-code-into-pure-pipelines
description: "Transforms complex, deeply nested imperative code into clean, testable pure functions organized as a sequential data pipeline."
---
# Refactor Nested Procedural Code into Pure Pipelines
Transforms complex, deeply nested imperative code into clean, testable pure functions organized as a sequential data pipeline.
## Prompt
```
Act as a Senior Software Engineer specializing in functional programming. I will provide a block of procedural code. Refactor it into a series of pure, single-responsibility functions that form a data pipeline. Follow these rules: 1. Remove all side effects from the logic; keep I/O at the boundaries. 2. Ensure every function is immutable and deterministic. 3. Provide a clear Type Signature comparison table showing the input and output types before and after the refactor. 4. Use a clear composition style to show how the functions link together. Output format: # Refactor Summary, ## Type Signature Comparison (Table), ## Refactored Pipeline Code, ## Implementation Notes. This is not a substitute for formal code review; consult your lead engineer for architectural alignment.
```
## Usage Notes
Use this with GitHub Copilot or Claude to clean up legacy spaghetti code or monolithic functions. Paste your nested function after the prompt. It works best for data transformation logic in languages like TypeScript, Python, or Rust.
Act as a Senior Software Engineer specializing in functional programming. I will provide a block of procedural code. Refactor it into a series of pure, single-responsibility functions that form a data pipeline. Follow these rules: 1. Remove all side effects from the logic; keep I/O at the boundaries. 2. Ensure every function is immutable and deterministic. 3. Provide a clear Type Signature comparison table showing the input and output types before and after the refactor. 4. Use a clear composition style to show how the functions link together. Output format: # Refactor Summary, ## Type Signature Comparison (Table), ## Refactored Pipeline Code, ## Implementation Notes. This is not a substitute for formal code review; consult your lead engineer for architectural alignment.Example output
Tips and common edits
Why this works
- Forces the model to strip away side effects, making code easier to test.
- The required type signature table highlights the shift from loose dicts to strict schemas.
- Pipeline composition creates a readable flow that replaces deeply nested if-else blocks.
Use this with GitHub Copilot or Claude to clean up legacy spaghetti code or monolithic functions. Paste your nested function after the prompt. It works best for data transformation logic in languages like TypeScript, Python, or Rust.
Common edits
- Adjust the naming conventions to match your existing codebase style.
- Add specific library requirements like Pydantic or Zod if you need runtime schema validation.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Refactor Monolithic God Classes into Clean Services
Get a step-by-step plan to break a large monolithic class into smaller, testable services while preserving the original public API behavior.
Refactor nested legacy loops into flat readable helper functions
Decompose deeply nested legacy loops into single-purpose functions. Use this when reviewing complex procedural code that is hard to test or debug.
Plan an incremental refactor for legacy code
Break down monolith or fragile legacy modules into safe, testable milestones using branch-by-abstraction patterns.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Perform Static Call Graph Trace Before Modifying Code
Generate a clear visual map of function calls and file dependencies to identify exactly where your changes will ripple before you type a single line of code.
Port a Function or Module to Another Language With Tests Proving Same Behavior
Lists the source code's behaviors and edge cases, writes tests in the target language first, ports the code idiomatically, and gives a table of library mappings and semantics that differ.
- Unit Test Plan and Test Code for an Existing Function
- Split a large pull request into reviewable commits
- Decompose monolithic automation into modular subflows
- Automated Dead Code Cleanup Plan for Codex Repositories
- Deconstruct Monolithic Pull Requests into Atomic Commit Stacks
- Sync Test Factories and Fixtures with Database Migrations