generalizing some indexed folds