Back to Lo

Core Meanby

docs/data/core-meanby.md

1.53.0231 B
Original Source

Calculates the mean of values computed by a predicate. Returns 0 for an empty collection.

go
list := []string{"aa", "bbb", "cccc", "ddddd"}
lo.MeanBy(list, func(item string) float64 {
    return float64(len(item))
})
// 3.5