Back to Lo

It Meanby

docs/data/it-meanby.md

1.53.0307 B
Original Source

Returns the mean value of the collection using the given transform function.

go
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