Add a utility that folds an iterator into a result and uses it to reduce boilerplate in the codebase.