mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.1 KiB
1.1 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ReduceLast | reducelast | it/seq.go#L153 | it | sequence |
|
|
|
54 |
Reduces a collection from right to left, returning a single value.
ReduceLast
result := it.ReduceLast(it.Range(1, 5), func(agg int, item int) int {
return agg - item
}, 0)
// -10 (0 - 4 - 3 - 2 - 1)
ReduceLastI
Reduces a collection from right to left, returning a single value. The accumulator function includes the index.
result := it.ReduceLastI(it.Range(1, 5), func(agg int, item int, index int) int {
return agg - item*index
}, 0)
// -20 (0 - 4*3 - 3*2 - 2*1 - 1*0)