pub trait AggBasic: IntoIterator + Sized {
// Provided methods
fn count_value(self, value: Self::Item) -> usize
where Self::Item: PartialEq { ... }
fn any(self) -> bool
where Self::Item: BoolType { ... }
fn all(self) -> bool
where Self::Item: BoolType { ... }
fn first(self) -> Option<Self::Item> { ... }
fn last(self) -> Option<Self::Item>
where Self::IntoIter: DoubleEndedIterator { ... }
fn n_sum(self) -> (usize, Option<Self::Item>)
where Self::Item: Zero { ... }
fn sum(self) -> Option<Self::Item>
where Self::Item: Zero { ... }
fn mean(self) -> Option<f64>
where Self::Item: Zero + Cast<f64> { ... }
fn max(self) -> Option<Self::Item>
where Self::Item: Number { ... }
fn min(self) -> Option<Self::Item>
where Self::Item: Number { ... }
fn argmax(self) -> Option<usize>
where Self::Item: PartialOrd { ... }
fn argmin(self) -> Option<usize>
where Self::Item: PartialOrd { ... }
}Provided Methods§
sourcefn count_value(self, value: Self::Item) -> usize
fn count_value(self, value: Self::Item) -> usize
Counts the occurrences of a specific value in the iterator.
This method iterates over the elements of the collection and counts
how many times the specified value appears.
§Arguments
self- The iterator to count values from.value- The value to count occurrences of.
§Returns
Returns the number of times the specified value appears in the iterator.
§Type Parameters
Self::Item- The type of items in the iterator, which must implementPartialEq.
§Examples
use tea_core::prelude::*;
let numbers = vec![1, 2, 3, 2, 4, 2];
assert_eq!(numbers.titer().count_value(2), 3);
assert_eq!(numbers.count_value(5), 0);sourcefn any(self) -> bool
fn any(self) -> bool
Checks if any element in the iterator satisfies a condition.
This method returns true if at least one element in the iterator
evaluates to true when converted to a boolean value.
§Returns
Returns true if any element is true, false otherwise.
§Type Parameters
Self::Item- The type of items in the iterator, which must implementBoolType.
§Examples
use tea_core::prelude::*;
let values = vec![false, false, true, false];
assert_eq!(values.any(), true);
let empty: Vec<bool> = vec![];
assert_eq!(empty.any(), false);sourcefn all(self) -> bool
fn all(self) -> bool
Checks if all elements in the iterator satisfy a condition.
This method returns true if all elements in the iterator
evaluate to true when converted to a boolean value.
§Returns
Returns true if all elements are true, false otherwise.
§Type Parameters
Self::Item- The type of items in the iterator, which must implementBoolType.
§Examples
use tea_core::prelude::*;
let values = vec![true, true, true];
assert_eq!(values.all(), true);
let mixed = vec![true, false, true];
assert_eq!(mixed.all(), false);
let empty: Vec<bool> = vec![];
assert_eq!(empty.all(), true);sourcefn first(self) -> Option<Self::Item>
fn first(self) -> Option<Self::Item>
Returns the first element of the iterator. If the iterator is empty, returns None.
sourcefn last(self) -> Option<Self::Item>where
Self::IntoIter: DoubleEndedIterator,
fn last(self) -> Option<Self::Item>where
Self::IntoIter: DoubleEndedIterator,
Returns the last element of the iterator. If the iterator is empty, returns None.
sourcefn mean(self) -> Option<f64>
fn mean(self) -> Option<f64>
Returns the mean of all elements in the iterator.
This method calculates the arithmetic mean of all elements in the iterator.
It first computes the sum and count of all elements using the n_sum method,
then divides the sum by the count to get the mean.
§Type Parameters
Self::Item: Must implementZeroand be castable tof64.
§Returns
Some(f64): The mean value if the iterator is not empty.None: If the iterator is empty.
§Examples
use tea_core::prelude::*;
let numbers = vec![1.0, 2.0, 3.0, 4.0, 5.0];
assert_eq!(numbers.titer().mean(), Some(3.0));
let empty: Vec<f64> = vec![];
assert_eq!(empty.titer().mean(), None);sourcefn max(self) -> Option<Self::Item>
fn max(self) -> Option<Self::Item>
Returns the maximum element in the iterator.
This method iterates through all elements and returns the maximum value.
§Type Parameters
Self::Item: Must implement theNumbertrait.
§Returns
Some(Self::Item): The maximum value if the iterator is not empty.None: If the iterator is empty.
§Examples
use tea_core::prelude::*;
use std::iter::empty;
let numbers = vec![1, 5, 3, 2, 4];
assert_eq!(AggBasic::max(numbers.titer()), Some(5));
let empty: Vec<i32> = vec![];
assert_eq!(AggBasic::max(empty.titer()), None);sourcefn min(self) -> Option<Self::Item>
fn min(self) -> Option<Self::Item>
Returns the minimum element in the iterator.
This method iterates through all elements and returns the minimum value.
§Type Parameters
Self::Item: Must implement theNumbertrait.
§Returns
Some(Self::Item): The minimum value if the iterator is not empty.None: If the iterator is empty.
§Examples
use tea_core::prelude::*;
use std::iter::empty;
let numbers = vec![5, 1, 3, 2, 4];
assert_eq!(AggBasic::min(numbers.titer()), Some(1));
let empty: Vec<i32> = vec![];
assert_eq!(AggBasic::min(empty.titer()), None);sourcefn argmax(self) -> Option<usize>where
Self::Item: PartialOrd,
fn argmax(self) -> Option<usize>where
Self::Item: PartialOrd,
Returns the index of the maximum element in the iterator.
This method iterates through all elements and returns the index of the maximum value.
§Type Parameters
Self::Item: Must implementPartialOrd.
§Returns
Some(usize): The index of the maximum value if the iterator is not empty.None: If the iterator is empty.
§Examples
use tea_core::prelude::*;
let numbers = vec![1, 5, 3, 2, 4];
assert_eq!(numbers.titer().argmax(), Some(1));
let empty: Vec<i32> = vec![];
assert_eq!(empty.titer().argmax(), None);sourcefn argmin(self) -> Option<usize>where
Self::Item: PartialOrd,
fn argmin(self) -> Option<usize>where
Self::Item: PartialOrd,
Returns the index of the minimum element in the iterator.
This method iterates through all elements and returns the index of the minimum value.
§Type Parameters
Self::Item: Must implementPartialOrd.
§Returns
Some(usize): The index of the minimum value if the iterator is not empty.None: If the iterator is empty.
§Examples
use tea_core::prelude::*;
let numbers = vec![5, 1, 3, 2, 4];
assert_eq!(numbers.titer().argmin(), Some(1));
let empty: Vec<i32> = vec![];
assert_eq!(empty.titer().argmin(), None);