Trait tea_core::prelude::AggBasic

source ·
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§

source

fn count_value(self, value: Self::Item) -> usize
where Self::Item: PartialEq,

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 implement PartialEq.
§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);
source

fn any(self) -> bool
where Self::Item: BoolType,

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 implement BoolType.
§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);
source

fn all(self) -> bool
where Self::Item: BoolType,

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 implement BoolType.
§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);
source

fn first(self) -> Option<Self::Item>

Returns the first element of the iterator. If the iterator is empty, returns None.

source

fn last(self) -> Option<Self::Item>

Returns the last element of the iterator. If the iterator is empty, returns None.

source

fn n_sum(self) -> (usize, Option<Self::Item>)
where Self::Item: Zero,

Returns the sum of all elements in the vector.

source

fn sum(self) -> Option<Self::Item>
where Self::Item: Zero,

Returns the sum of all elements in the vector.

source

fn mean(self) -> Option<f64>
where Self::Item: Zero + Cast<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 implement Zero and be castable to f64.
§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);
source

fn max(self) -> Option<Self::Item>
where Self::Item: Number,

Returns the maximum element in the iterator.

This method iterates through all elements and returns the maximum value.

§Type Parameters
  • Self::Item: Must implement the Number trait.
§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);
source

fn min(self) -> Option<Self::Item>
where Self::Item: Number,

Returns the minimum element in the iterator.

This method iterates through all elements and returns the minimum value.

§Type Parameters
  • Self::Item: Must implement the Number trait.
§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);
source

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 implement PartialOrd.
§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);
source

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 implement PartialOrd.
§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);

Object Safety§

This trait is not object safe.

Implementors§