I love this! I had this exact problem last week and I fell into the same solution. It really bothered me that I had so much duplicate code.
Glad you wrote this up. Highly readable (which I love) and a great tip for everyone.
Nicely done Bryan!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.