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

662 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
SumBy sumby it/math.go#L74 it math
func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](collection iter.Seq[T], transform func(item T) R) R
it#math#sumby
core#slice#sumby
core#slice#sum
65

Returns the sum of values in the collection using the given transform function.

type Person struct {
    Name string
    Age  int
}

people := it.Slice([]Person{
    {"Alice", 25},
    {"Bob", 30},
    {"Charlie", 35},
})

result := it.SumBy(people, func(p Person) int {
    return p.Age
})
// 90