pub trait MapBasic: TrustedLenwhere
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§
Sourcefn abs(self) -> impl TrustedLen<Item = Self::Item>
fn abs(self) -> impl TrustedLen<Item = Self::Item>
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]);Sourcefn shift<'a>(
self,
n: i32,
value: Self::Item,
) -> Box<dyn TrustedLen<Item = Self::Item> + 'a>
fn shift<'a>( self, n: i32, value: Self::Item, ) -> Box<dyn TrustedLen<Item = Self::Item> + 'a>
Shifts the elements of the iterator by n positions, filling in with the provided value.
- If
nis positive, shifts right and prependsvalue. - If
nis negative, shifts left and appendsvalue. - If
nis 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.