mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
Fixed 5 linter issues identified in quality assessment: - first_test.go: Check error return in BenchmarkFirst - parallel_map_test.go: Check error returns in benchmarks (2 locations) - parallel_reduce_test.go: Check error return in BenchmarkParallelReduce - foldright.go: Fix comment formatting (proper indentation) All tests pass. Linter now reports 0 issues. Quality score: 9.6/10 → 10.0/10 (perfect) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
14 lines
416 B
Go
14 lines
416 B
Go
package underscore
|
|
|
|
// FoldRight is like Reduce but processes elements from right to left.
|
|
// Also known as foldr in Haskell.
|
|
//
|
|
// Example: FoldRight([]int{1,2,3}, 0, func(n, acc int) int { return n - acc })
|
|
//
|
|
// → 1 - (2 - (3 - 0)) = 1 - (2 - 3) = 1 - (-1) = 2
|
|
func FoldRight[T, P any](values []T, acc P, fn func(T, P) P) P {
|
|
for i := len(values) - 1; i >= 0; i-- {
|
|
acc = fn(values[i], acc)
|
|
}
|
|
return acc
|
|
}
|