base/reduce.jl: dry up the foldl and foldr functions a bit.