Add a helper to reduce duplicate code.

This is not performance critical.  I wonder if compilers can inline
closures?