Wrap redundant reduce and reduceRight code in helper

The loops could be further abstracted, but I didn't like how it looked after going that far

Fixes #1734 
If you're passing in `dir`, can't `wrapReduce` subsume the loop as well?