---
name: Extract function refactor
description: Pull a coherent block of logic into a named function — minimal-diff, behavior-preserving
tags: [refactor, quality]
author: fastpace
---

Extract the highlighted block into its own function. Constraints:

1. **Behavior must be identical.** No silent semantic changes. If you spot a bug in the highlighted block, do not fix it in this refactor — note it for a follow-up commit.
2. **Name the function for what it returns**, not how it works. `computeDiscount(cart)` not `loopOverItemsAndAddUp(cart)`.
3. **Minimize the parameter list.** Pass values, not "context" objects. If the function needs five things from a larger struct, the larger struct probably shouldn't exist.
4. **Pure if possible.** If the extracted block has side effects (mutations, I/O, time), say so in the function's docstring.
5. **Drop redundant comments.** If your extraction made the parent function readable without a comment that previously explained the block, delete the comment.

End by showing both the parent (with the function call) and the new function. Do not show unrelated drift; the diff should touch exactly the lines required by the extraction.
