MapBasic

Trait MapBasic 

Source
pub trait MapBasic: TrustedLen
where Self: Sized,
{ // Provided methods fn abs(self) -> impl TrustedLen<Item = Self::Item> where Self::Item: Number { ... } fn shift<'a>( self, n: i32, value: Self::Item, ) -> Box<dyn TrustedLen<Item = Self::Item> + 'a> where Self::Item: Clone + 'a, Self: Sized + 'a { ... } }
Expand description

A trait for basic mapping operations on trusted length iterators.

This trait provides methods for common operations like absolute value and shifting, which can be applied to iterators with a known length.

Provided Methods§

Source

fn abs(self) -> impl TrustedLen<Item = Self::Item>
where Self::Item: Number,

Applies the absolute value function to each element in the iterator.

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

let v = vec![-1, 2, -3, 4, -5];
let result: Vec<_> = v.titer().abs().collect();
assert_eq!(result, vec![1, 2, 3, 4, 5]);
Source

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

Shifts the elements of the iterator by n positions, filling in with the provided value.

  • If n is positive, shifts right and prepends value.
  • If n is negative, shifts left and appends value.
  • If n is zero, returns the original iterator.
§Examples
use tea_core::prelude::*;
use tea_map::MapBasic;

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

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

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§