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.
There are a pair of research languages called Harmony and Boomerang [1] that does this with what they call "lenses". There are also some easy-reading introductory slides [2,3].
I don't think anything happened to it since the hackathon. Judging by own experience with hackathons, I wouldn't expect too much in the way of code quality. (Reading some of my old hackathon code still makes me shudder :)).
Unfortunately, I don't think he found it particularly useful and gave up on it after the hackathon. Still, it was a cool project.