Back to Lo

It Mean

docs/data/it-mean.md

1.53.0406 B
Original Source

Computes the arithmetic mean. MeanBy applies a transform before averaging. Returns 0 for empty sequences.

Examples:

go
avg := it.Mean(iter.Seq[int](func(y func(int) bool){ _ = y(2); _ = y(3); _ = y(5) }))
// avg == 10/3 == 3 (int division)
go
avg := it.MeanBy(iter.Seq[string](func(y func(string) bool){ _ = y("aa"); _ = y("bbb") }), func(s string) int { return len(s) })
// (2+3)/2 == 2