replacing the current [[accumulate]] implementation: shorter and simpler, and also supports non-void return types