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

645 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
MeanBy meanby it/math.go#L106 it math
func MeanBy[T any, R constraints.Float | constraints.Integer](collection iter.Seq[T], transform func(item T) R) R
it#math#mean
core#slice#meanby
core#slice#mean
70

Returns the mean value of 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.MeanBy(people, func(p Person) int {
    return p.Age
})
// 30.0