Files
lo/docs/data/it-reducelast.md
T
2025-10-08 14:55:05 +02:00

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
func ReduceLast[T, R any](collection iter.Seq[T], accumulator func(agg R, item T) R, initial R) R
func ReduceLastI[T, R any](collection iter.Seq[T], accumulator func(agg R, item T, index int) R, initial R) R
it#sequence#reduce
it#sequence#reducei
it#sequence#reducelast
it#sequence#reducelasti
core#slice#reducelast
core#slice#reducelasti
core#slice#reduce
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)