1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Numeric averaging.
//
// Spliced into the `FluentIter` trait by `build.rs`. Names resolve in
// the crate-root scope of `lib.rs`, exactly as before the split.
/// ⇔ `.avg()`: arithmetic mean as `Option<f64>` — `None` on empty
/// (JS returns `NaN`; Rust says it in the type).
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// assert_eq!([2, 4, 6].into_iter().avg(), Some(4.0));
/// assert_eq!(std::iter::empty::<i32>().avg(), None);
/// ```
/// ⇔ `.avg(mapFn)`: mean of a projection.
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// let rows = [("x", 10.0), ("y", 20.0)];
/// assert_eq!(rows.into_iter().avg_by(|(_, v)| *v), Some(15.0));
/// ```