AI Blocks › Build and ship software
Pure function refactoring planner
Paste a messy function. Get its hidden state listed, a safer version that uses only its inputs, and tests.
Pure function refactoring planner is a free AI skill for the job "Build and ship software". Give the instructions to an AI assistant that supports the required files and tools, then review its output.
Free · No account · Made by AI Blocks · Level: advanced · Thinking: high
What it does
Most hard-to-find bugs come from state that is not what you think it is. A function that reads a global value, a setting or a shared list gives different answers at different times. A function that also changes them leaves traces you cannot see from the call. This skill lists every outside thing the function reads and every change it makes, and writes that list as a comment above it. It then plans a pure version, which depends only on what you hand it and returns results, and a thin layer around it that does the outside work. It writes tests with plain inputs and outputs, states the cost of copying, and flags functions that need a dozen inputs as needing a redesign.
You give it
- The function, pasted in full, and the code it calls (the more the better)
- What it should do, and one case where it goes wrong (optional)
- Any speed limits or how often it runs (optional)
- A draft (optional)
You get
- A list of every outside value it reads and every change it makes
- A plan for a pure function and a thin layer for the outside effects
- Plain tests for the pure part
- A note on the copying cost and where in-place change is still worth it
Use it when
- A function gives different answers on different runs and you cannot see why.
- You cannot write a test for a function without setting up half the program.
- A change in one place keeps breaking something in another.
How to use it
- Start a chat with the skill. Open it if you added it to your AI, or copy it and paste it in.
- Paste the one function you find hardest to trust, plus the code it calls.
- Say what it should do and describe the case where it goes wrong.
- Read the hidden state list first. Correct anything it missed.
- Run the tests against the old function and the new plan, and compare.