This reminds me of my friend's project for a recent hackathon where he implemented a language that guaranteed every function in it was reversible. It would let you do something like this for any function.
Unfortunately, I don't think he found it particularly useful and gave up on it after the hackathon. Still, it was a cool project.