0
Turn a god function into composable, testable units
I have a function that has grown too large and does too many things. Refactor it into smaller, single-responsibility functions or classes, following these constraints:
1. Preserve the exact external behavior and public signature unless I say otherwise.
2. Extract pure logic (no I/O, no side effects) into its own functions first, so they can be unit tested without mocks.
3. Name each extracted piece for what it does, not how it does it.
4. Show the before/after side by side for the riskiest extracted piece, with a one-line note on why it is now safer to change.
5. List any behavior that is ambiguous in the original code (e.g. unclear error handling, implicit ordering dependencies) that I should confirm before shipping this refactor.
6. Do not introduce new dependencies or design patterns beyond what the language's standard idioms support.
Language/framework: language
Function to refactor:
code
What it's used for / calling context: context