MapValidBasic

Trait MapValidBasic 

Source
pub trait MapValidBasic<T: IsNone>: TrustedLen<Item = T> + Sized {
Show 13 methods // Provided methods fn vabs(self) -> impl TrustedLen<Item = T> where T::Inner: Number { ... } fn ffill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: Option<T>, ) -> impl TrustedLen<Item = T> { ... } fn ffill(self, value: Option<T>) -> impl TrustedLen<Item = T> { ... } fn bfill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: Option<T>, ) -> impl TrustedLen<Item = T> where Self: DoubleEndedIterator<Item = T> { ... } fn bfill(self, value: Option<T>) -> impl TrustedLen<Item = T> where Self: DoubleEndedIterator<Item = T> { ... } fn vclip<'a>(self, lower: T, upper: T) -> Box<dyn TrustedLen<Item = T> + 'a> where T::Inner: PartialOrd, T: 'a, Self: 'a { ... } fn fill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: T, ) -> impl TrustedLen<Item = T> { ... } fn fill(self, value: T) -> impl TrustedLen<Item = T> { ... } fn vshift<'a>( self, n: i32, value: Option<T>, ) -> Box<dyn TrustedLen<Item = T> + 'a> where T: Clone + 'a, Self: 'a { ... } fn drop_none(self) -> impl Iterator<Item = T> { ... } fn vcut<'a, V2, V3, T2>( self, bins: &'a V2, labels: &'a V3, right: bool, add_bounds: bool, ) -> TResult<Box<dyn TrustedLen<Item = TResult<T2>> + 'a>> where Self: 'a, T::Inner: Number + Debug, (T::Inner, T::Inner): HomogeneousTuple<Item = T::Inner>, T2: IsNone + 'a, V2: Vec1View<T>, V3: Vec1View<T2> { ... } fn vsorted_unique_idx<'a>( self, keep: Keep, ) -> Box<dyn Iterator<Item = usize> + 'a> where T::Inner: PartialEq + 'a + Debug, Self: 'a { ... } fn vsorted_unique<'a>(self) -> impl Iterator<Item = T> + 'a where T::Inner: PartialEq + 'a, Self: 'a { ... }
}

Provided Methods§

Source

fn vabs(self) -> impl TrustedLen<Item = T>
where T::Inner: Number,

Computes the absolute value of each element in the iterator, ignoring None values.

This method is similar to abs(), but it can handle None values.

§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(-1), None, Some(2), Some(-3)];
let result: Vec<_> = v.titer().vabs().collect();
assert_eq!(result, vec![Some(1), None, Some(2), Some(3)]);

See also: abs()

Source

fn ffill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: Option<T>, ) -> impl TrustedLen<Item = T>

Forward fill values where the mask is true, ignoring None values.

§Arguments
  • mask_func - A function that returns true for values that should be filled.
  • value - An optional value to fill if head values are still None after forward fill.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(2), None, Some(3)];
let result: Vec<_> = v.titer().ffill_mask(|x| x.is_none(), Some(Some(0))).collect();
assert_eq!(result, vec![Some(1), Some(1), Some(2), Some(2), Some(3)]);
Source

fn ffill(self, value: Option<T>) -> impl TrustedLen<Item = T>

Forward fill None values.

This method is similar to ffill(), but it can handle None values.

§Arguments
  • value - An optional value to fill if head values are still None after forward fill.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(2), None, Some(3)];
let result: Vec<_> = v.titer().ffill(Some(Some(0))).collect();
assert_eq!(result, vec![Some(1), Some(1), Some(2), Some(2), Some(3)]);
Source

fn bfill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: Option<T>, ) -> impl TrustedLen<Item = T>
where Self: DoubleEndedIterator<Item = T>,

Backward fill values where the mask is true, ignoring None values.

§Arguments
  • mask_func - A function that returns true for values that should be filled.
  • value - An optional value to fill if tail values are still None after backward fill.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(2), None, Some(3)];
let result: Vec<_> = v.titer().bfill_mask(|x| x.is_none(), Some(Some(0))).collect();
assert_eq!(result, vec![Some(1), Some(2), Some(2), Some(3), Some(3)]);
Source

fn bfill(self, value: Option<T>) -> impl TrustedLen<Item = T>
where Self: DoubleEndedIterator<Item = T>,

Backward fill None values.

This method is similar to bfill(), but it can handle None values.

§Arguments
  • value - An optional value to fill if tail values are still None after backward fill.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(2), None, Some(3)];
let result: Vec<_> = v.titer().bfill(Some(Some(0))).collect();
assert_eq!(result, vec![Some(1), Some(2), Some(2), Some(3), Some(3)]);
Source

fn vclip<'a>(self, lower: T, upper: T) -> Box<dyn TrustedLen<Item = T> + 'a>
where T::Inner: PartialOrd, T: 'a, Self: 'a,

Clip (limit) the values in an iterator, ignoring None values.

This method is similar to clip(), but it can handle None values.

§Arguments
  • lower - The lower bound.
  • upper - The upper bound.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(3), Some(5), Some(7)];
let result: Vec<_> = v.titer().vclip(Some(2), Some(6)).collect();
assert_eq!(result, vec![Some(2), None, Some(3), Some(5), Some(6)]);
Source

fn fill_mask<F: Fn(&T) -> bool>( self, mask_func: F, value: T, ) -> impl TrustedLen<Item = T>

Fill values where the mask is true, ignoring None values.

§Arguments
  • mask_func - A function that returns true for values that should be filled.
  • value - The value to fill with.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(3), Some(4), Some(5)];
let result: Vec<_> = v.titer().fill_mask(|x| x.map_or(false, |v| v % 2 == 0), Some(0)).collect();
assert_eq!(result, vec![Some(1), None, Some(3), Some(0), Some(5)]);
Source

fn fill(self, value: T) -> impl TrustedLen<Item = T>

Fill None values with a specified value.

This method is similar to fill(), but it can handle None values.

§Arguments
  • value - The value to fill None values with.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(3), None, Some(5)];
let result: Vec<_> = v.titer().fill(Some(0)).collect();
assert_eq!(result, vec![Some(1), Some(0), Some(3), Some(0), Some(5)]);
Source

fn vshift<'a>( self, n: i32, value: Option<T>, ) -> Box<dyn TrustedLen<Item = T> + 'a>
where T: Clone + 'a, Self: 'a,

Shift the elements in the iterator, ignoring None values.

This method is similar to shift(), but it can handle None values.

§Arguments
  • n - The number of positions to shift. Positive values shift right, negative values shift left.
  • value - An optional value to fill the vacated positions.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(3), Some(4), Some(5)];
let result: Vec<_> = v.titer().vshift(2, Some(Some(0))).collect();
assert_eq!(result, vec![Some(0), Some(0), Some(1), None, Some(3)]);

See also: shift()

Source

fn drop_none(self) -> impl Iterator<Item = T>

Drop None values from the iterator.

§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), None, Some(3), None, Some(5)];
let result: Vec<_> = v.titer().drop_none().collect();
assert_eq!(result, vec![Some(1), Some(3), Some(5)]);
Source

fn vcut<'a, V2, V3, T2>( self, bins: &'a V2, labels: &'a V3, right: bool, add_bounds: bool, ) -> TResult<Box<dyn TrustedLen<Item = TResult<T2>> + 'a>>
where Self: 'a, T::Inner: Number + Debug, (T::Inner, T::Inner): HomogeneousTuple<Item = T::Inner>, T2: IsNone + 'a, V2: Vec1View<T>, V3: Vec1View<T2>,

Categorize values into bins.

This function categorizes the values in the iterator into bins defined by the bins parameter. It assigns labels to each bin as specified by the labels parameter.

§Arguments
  • bins - A slice of bin edges.
  • labels - A slice of labels for each bin.
  • right - If true, intervals are closed on the right. If false, intervals are closed on the left.
  • add_bounds - If true, adds -∞ and +∞ as the first and last bin edges respectively.
§Returns

Returns a TResult containing a boxed TrustedLen iterator of TResult<T2> items.

§Errors

Returns an error if:

  • The number of labels doesn’t match the number of bins (accounting for add_bounds).
  • A value falls outside the bin ranges.
§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![1, 3, 5, 7, 9];
let bins = vec![4, 8];
let labels = vec!["low", "medium", "high"];
let result: Vec<_> = v.titer().vcut(&bins, &labels, true, true).unwrap().collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(result, vec!["low", "low", "medium", "medium", "high"]);
Source

fn vsorted_unique_idx<'a>( self, keep: Keep, ) -> Box<dyn Iterator<Item = usize> + 'a>
where T::Inner: PartialEq + 'a + Debug, Self: 'a,

Returns indices of unique elements in a sorted iterator, keeping either the first or last occurrence.

§Arguments
  • keep - Specifies whether to keep the first or last occurrence of each unique element.
§Returns

A boxed iterator yielding indices of unique elements.

§Examples
use tea_core::prelude::*;
use tea_map::{MapValidBasic, Keep};

let v = vec![Some(1), Some(1), Some(2), Some(2), Some(3)];
let result: Vec<_> = v.titer().vsorted_unique_idx(Keep::First).collect();
assert_eq!(result, vec![0, 2, 4]);

let result: Vec<_> = v.titer().vsorted_unique_idx(Keep::Last).collect();
assert_eq!(result, vec![1, 3, 4]);
Source

fn vsorted_unique<'a>(self) -> impl Iterator<Item = T> + 'a
where T::Inner: PartialEq + 'a, Self: 'a,

Returns an iterator over unique elements in a sorted iterator.

This method removes consecutive duplicate elements from the iterator.

§Returns

An iterator yielding unique elements.

§Examples
use tea_core::prelude::*;
use tea_map::MapValidBasic;

let v = vec![Some(1), Some(1), Some(2), Some(2), Some(3)];
let result: Vec<_> = v.titer().vsorted_unique().collect();
assert_eq!(result, vec![Some(1), Some(2), Some(3)]);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: IsNone, I: TrustedLen<Item = T>> MapValidBasic<T> for I