pub trait IterExtd: Iterator {
Show 28 methods
// Provided methods
fn arr_chunks<const N: usize>(self) -> ArrChunks<Self, N> ⓘ
where Self: Sized { ... }
fn array_cloned<'a, T, const N: usize>(self) -> ArrayCloned<Self, N> ⓘ
where Self: Sized + Iterator<Item = [&'a T; N]>,
T: Clone + 'a { ... }
fn array_copied<'a, T, const N: usize>(self) -> ArrayCopied<Self, N> ⓘ
where Self: Sized + Iterator<Item = [&'a T; N]>,
T: Copy + 'a { ... }
fn collect_arr_zeroed<const N: usize>(self) -> (usize, [Self::Item; N])
where Self: Sized + Iterator,
Self::Item: AllowZero { ... }
fn collect_array<const N: usize>(self) -> [<Self as Iterator>::Item; N]
where Self: Sized + Iterator { ... }
fn consume(self)
where Self: Sized { ... }
fn combine_iters<J>(
self,
self_part_len: usize,
other_iter: J,
other_part_len: usize,
) -> CombineIters<Self, J> ⓘ
where J: Iterator,
Self: Sized { ... }
fn count_freq(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
where Self: Sized,
Self::Item: Eq + Hash + Debug { ... }
fn extrapolate(self) -> Extrapolate<Self> ⓘ
where Self: Sized,
Self::Item: Zero { ... }
fn gcd(self) -> Option<<<Self as Iterator>::Item as Deref>::Target>
where Self: Sized,
<Self as Iterator>::Item: Deref,
<<Self as Iterator>::Item as Deref>::Target: Integer + Copy { ... }
fn step_boundary(self, size: usize) -> StepBoundary<Self> ⓘ
where Self: Sized { ... }
fn inclusive_step_by(self, step: usize) -> InclusiveStepBy<Self> ⓘ
where Self: Sized { ... }
fn map_by_two<B, F>(self, f: F) -> MapByTwo<Self, F> ⓘ
where F: FnMut(Self::Item, Self::Item) -> B,
Self: Sized { ... }
fn map_by_three<B, F>(self, f: F) -> MapByThree<Self, F> ⓘ
where F: FnMut(Self::Item, Self::Item, Self::Item) -> B,
Self: Sized { ... }
fn map_iters<K, F, B>(self, k: K, f: F) -> MapIters<Self, K, F> ⓘ
where K: Iterator,
F: FnMut(&mut Self, &mut K) -> Option<B>,
Self: Sized { ... }
fn missing_integers(self) -> MissingIntegers<Self> ⓘ
where Self: Iterator + Sized + Clone,
<Self as Iterator>::Item: PartialOrd + Deref,
<<Self as Iterator>::Item as Deref>::Target: Copy,
usize: TryFromByAdd<<<Self as Iterator>::Item as Deref>::Target> { ... }
fn missing_integers_uqsort(
self,
) -> impl Iterator<Item = <Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item> + Debug
where Self: Iterator + Sized + Clone + Debug,
<Self as Iterator>::Item: PartialOrd + Deref + Debug,
<<Self as Iterator>::Item as Deref>::Target: Copy + Debug + ToZero<<<Self as Iterator>::Item as Deref>::Target>,
Range<<<Self as Iterator>::Item as Deref>::Target>: Iterator,
<Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item: PartialOrd<<<Self as Iterator>::Item as Deref>::Target> { ... }
fn modes(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
where Self: Sized,
Self::Item: Eq + Hash + Debug { ... }
fn previous(self, item: Self::Item) -> Previous<Self> ⓘ
where Self: Sized,
Self::Item: Clone { ... }
fn last_taken(self) -> LastTaken<Self> ⓘ
where Self: Sized { ... }
fn slice_copied<const N: usize>(self) -> SliceCopied<Self, N> ⓘ
where Self: Sized + Clone { ... }
fn skip_step_by(self, skip: usize, step: usize) -> SkipStepBy<Self> ⓘ
where Self: Sized { ... }
fn step_by_fn<F>(self, f: F) -> StepByFn<Self, F> ⓘ
where Self: Sized,
F: FnMut(&mut usize) -> usize { ... }
fn to_range_icv(self) -> TupToRangeIcv<Self> ⓘ
where Self: Sized { ... }
fn to_range(self) -> TupToRange<Self> ⓘ
where Self: Sized { ... }
fn to_tuple(self) -> RangeToTup<Self> ⓘ
where Self: Sized { ... }
fn to_tuple_icv(self) -> RangeIcvToTup<Self> ⓘ
where Self: Sized { ... }
fn unique_sorted(self) -> UniqueSorted<Self>
where Self: Iterator + Sized + Clone,
<Self as Iterator>::Item: PartialOrd + Deref,
<<Self as Iterator>::Item as Deref>::Target: Copy,
usize: TryFromByAdd<<<Self as Iterator>::Item as Deref>::Target> { ... }
}
Expand description
Trait extends the functionality of the standard iterator.
This trait provides additional methods for working with iterators, enhancing their functionality.
Provided Methods§
sourcefn arr_chunks<const N: usize>(self) -> ArrChunks<Self, N> ⓘwhere
Self: Sized,
fn arr_chunks<const N: usize>(self) -> ArrChunks<Self, N> ⓘwhere
Self: Sized,
Returns an iterator over the N elements of the base iterator per iteration.
§Panics
Panics if N is 0.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = "functions";
let iter = arr.chars().arr_chunks();
let vec_arrs: Vec<[char; 4]> = iter.collect();
assert_eq!(vec_arrs, vec![['f', 'u', 'n', 'c'], ['t', 'i', 'o', 'n']]);
sourcefn array_cloned<'a, T, const N: usize>(self) -> ArrayCloned<Self, N> ⓘ
fn array_cloned<'a, T, const N: usize>(self) -> ArrayCloned<Self, N> ⓘ
Creates an iterator that clones all elements of its arrays.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec!["iter".to_string(), "array".to_string(), "chunk".to_string(), "pointer".to_string()];
let iter = vec.iter().arr_chunks::<2>().array_cloned();
let vec_cloned = iter.collect::<Vec<_>>();
assert_eq!(vec_cloned, vec![["iter".to_string(), "array".to_string()], ["chunk".to_string(), "pointer".to_string()]]);
sourcefn array_copied<'a, T, const N: usize>(self) -> ArrayCopied<Self, N> ⓘ
fn array_copied<'a, T, const N: usize>(self) -> ArrayCopied<Self, N> ⓘ
Creates an iterator that copies all elements of its arrays.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec![1, 2, 3, 4, 5];
let iter = vec.iter().arr_chunks::<2>().array_copied();
let vec_copied = iter.collect::<Vec<_>>();
assert_eq!(vec_copied, vec![[1, 2], [3, 4]]);
sourcefn collect_arr_zeroed<const N: usize>(self) -> (usize, [Self::Item; N])
fn collect_arr_zeroed<const N: usize>(self) -> (usize, [Self::Item; N])
Collect a zeroed array for nullable types.
§Panics
Panics if N is 0.
§Examples
Basic usage:
use iterextd::IterExtd;
let val = "The current year is 2024.";
let iter = val.chars().filter(|elem| elem.is_ascii_digit());
let arr: (usize, [char; 8]) = iter.collect_arr_zeroed();
assert_eq!(arr, (4, ['2', '0', '2', '4', '\0', '\0', '\0', '\0']));
sourcefn collect_array<const N: usize>(self) -> [<Self as Iterator>::Item; N]
fn collect_array<const N: usize>(self) -> [<Self as Iterator>::Item; N]
Create an array from an iterator.
§Panics
Panics if N is 0 or N greater than the length of the iterator.
§Examples
Basic usage:
use iterextd::IterExtd;
let val = vec!["The", "current", "year", "is", "2024."];
let iter = val.into_iter();
let arr: [&str; 2] = iter.collect_array();
assert_eq!(arr, ["The", "current"]);
sourcefn consume(self)where
Self: Sized,
fn consume(self)where
Self: Sized,
Consumes an iterator, returns nothing.
§Examples
Basic usage:
use iterextd::IterExtd;
let mut arr = [200, 201, 202, 203];
let _ = arr.iter_mut().map(|elem| { *elem +=10;}).consume();
assert_eq!(arr, [210, 211, 212, 213]);
sourcefn combine_iters<J>(
self,
self_part_len: usize,
other_iter: J,
other_part_len: usize,
) -> CombineIters<Self, J> ⓘ
fn combine_iters<J>( self, self_part_len: usize, other_iter: J, other_part_len: usize, ) -> CombineIters<Self, J> ⓘ
Combine two iterators in parts sequentially. The length of the piece can be set for each separately.
§Panics
Panics if both basic_repeats
and other_repeats
are 0.
§Examples
Basic usage:
use iterextd::IterExtd;
let rgb_iter = [200u8, 110, 25, 73, 49, 155, 16, 57, 180].into_iter();
let alpha_iter = [10u8, 20, 30, 40, 50].into_iter();
let rgba = rgb_iter.combine_iters(3, alpha_iter, 1).collect::<Vec<u8>>();
assert_eq!(rgba, vec![200u8, 110, 25, 10, 73, 49, 155, 20, 16, 57, 180, 30]);
sourcefn count_freq(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
fn count_freq(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
Counts the frequency of each element in the iterator.
§Warning
The results are stored in a HashMap
, which does not preserve the order of the elements.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec![1, 2, 2, 3, 3, 3];
let mut freqs = vec.into_iter().count_freq().collect::<Vec<_>>();
freqs.sort();
assert_eq!(freqs, vec![(1, 1), (2, 2), (3, 3)]);
sourcefn extrapolate(self) -> Extrapolate<Self> ⓘ
fn extrapolate(self) -> Extrapolate<Self> ⓘ
Extrapolates the iterator’s elements.
§Panics
This method will panic in debug mode if the extrapolated values cause a computation overflow.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr: [f32; 2] = [0.00, 0.01];
let extrapolated = arr.into_iter().extrapolate().take(5).collect::<Vec<_>>();
assert_eq!(extrapolated, vec![0.0, 0.01, 0.02, 0.03, 0.04]);
let vec = vec![2, 5, 6, 9, 13];
let extrapolated: Vec<_> = vec.into_iter().extrapolate().take(10).collect();
assert_eq!(extrapolated, vec![2, 5, 6, 9, 13, 17, 21, 25, 29, 33]);
sourcefn gcd(self) -> Option<<<Self as Iterator>::Item as Deref>::Target>
fn gcd(self) -> Option<<<Self as Iterator>::Item as Deref>::Target>
Finds the greatest common divisor (GCD) of the elements in the iterator.
§Notes
- NOTE: This method will return
None
if the iterator is empty. - NOTE: The minimum sequence length must be two elements; otherwise,
None
will be returned.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec![24, 36, 48];
assert_eq!(vec.iter().gcd(), Some(12));
let empty_vec: Vec<i32> = vec![];
assert_eq!(empty_vec.iter().gcd(), None);
let single_element = vec![42];
assert_eq!(single_element.iter().gcd(), None);
sourcefn step_boundary(self, size: usize) -> StepBoundary<Self> ⓘwhere
Self: Sized,
fn step_boundary(self, size: usize) -> StepBoundary<Self> ⓘwhere
Self: Sized,
Create an indexes iterator with a start and end for each step.
With each iteration, it furnishes the start and end indices of the current step, while also accounting for any residual elements in the last incomplete step.
§Panics
Panics if the step size is zero.
§Examples
Basic usage:
use iterextd::IterExtd;
let s = "slice index iterator";
let iter = (0..s.len()).step_boundary(3);
iter.for_each(|bounds| { println!("{:?}", &s[bounds.0..=bounds.1] ); });
sourcefn inclusive_step_by(self, step: usize) -> InclusiveStepBy<Self> ⓘwhere
Self: Sized,
fn inclusive_step_by(self, step: usize) -> InclusiveStepBy<Self> ⓘwhere
Self: Sized,
Creates an iterator that performs the given step at each iteration, returning inclusive of the first and last element.
If there are elements smaller than the remaining step, the last element will be returned.
§Panics
Panics if the step size is zero.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let iter = arr.into_iter().inclusive_step_by(4);
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![0, 4, 8, 9]);
sourcefn map_by_two<B, F>(self, f: F) -> MapByTwo<Self, F> ⓘ
fn map_by_two<B, F>(self, f: F) -> MapByTwo<Self, F> ⓘ
Creates an iterator that yields two elements per iteration.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let iter = arr.iter().map_by_two(|a, b| { Into::into(*a + *b) });
let vec = iter.collect::<Vec<u32>>();
assert_eq!(vec, vec![3, 7, 11, 15, 19]);
sourcefn map_by_three<B, F>(self, f: F) -> MapByThree<Self, F> ⓘ
fn map_by_three<B, F>(self, f: F) -> MapByThree<Self, F> ⓘ
Creates an iterator that yields three elements per iteration.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
let iter = arr.into_iter().map_by_three(|a, b, c| { [c, a, b] } );
let vec = iter.flatten().collect::<Vec<_>>();
assert_eq!(vec, vec![2, 0, 1, 5, 3, 4, 8, 6, 7, 11, 9, 10, 14, 12, 13]);
sourcefn map_iters<K, F, B>(self, k: K, f: F) -> MapIters<Self, K, F> ⓘ
fn map_iters<K, F, B>(self, k: K, f: F) -> MapIters<Self, K, F> ⓘ
Creates an iterator that yields two iterators per iteration.
§Examples
Basic usage:
use iterextd::IterExtd;
let self_arr: [u16; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let oth_arr: [&u8; 5] = [&20, &21, &22, &23, &24];
let self_iter = self_arr.iter();
let other_iter = oth_arr.iter();
let iter = self_iter
.map_iters(
other_iter.clone(), |s, o| { Some([*s.next()?, *s.next()?, *s.next()?, (*(*o.next()?)).into()]) }
);
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![[1, 2, 3, 20], [4, 5, 6, 21], [7, 8, 9, 22]]);
sourcefn missing_integers(self) -> MissingIntegers<Self> ⓘ
fn missing_integers(self) -> MissingIntegers<Self> ⓘ
Return an iterator adapter that yields missing integers.
Note that the maximum value of an iterator element must be less than or equal to
usize::MAX
for unsigned type and isize::MAX for signed
!
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [9u8, 5, 6, 4, 8, 8, 2, 4, 10, 2, 12];
let vec = arr.iter().missing_integers().collect::<Vec<_>>();
assert_eq!(vec, vec![3, 7, 11]);
sourcefn missing_integers_uqsort(
self,
) -> impl Iterator<Item = <Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item> + Debugwhere
Self: Iterator + Sized + Clone + Debug,
<Self as Iterator>::Item: PartialOrd + Deref + Debug,
<<Self as Iterator>::Item as Deref>::Target: Copy + Debug + ToZero<<<Self as Iterator>::Item as Deref>::Target>,
Range<<<Self as Iterator>::Item as Deref>::Target>: Iterator,
<Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item: PartialOrd<<<Self as Iterator>::Item as Deref>::Target>,
fn missing_integers_uqsort(
self,
) -> impl Iterator<Item = <Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item> + Debugwhere
Self: Iterator + Sized + Clone + Debug,
<Self as Iterator>::Item: PartialOrd + Deref + Debug,
<<Self as Iterator>::Item as Deref>::Target: Copy + Debug + ToZero<<<Self as Iterator>::Item as Deref>::Target>,
Range<<<Self as Iterator>::Item as Deref>::Target>: Iterator,
<Range<<<Self as Iterator>::Item as Deref>::Target> as Iterator>::Item: PartialOrd<<<Self as Iterator>::Item as Deref>::Target>,
Returns an iterator adapter that finds missing integers. This adapter must use a unique and sorted iterator.
§Examples
Basic usage:
use iterextd::IterExtd;
let mut vec = vec![-2i8, 2, 4, 5, 6, 8, 9, 10, 12];
let mut iter = vec.iter().missing_integers_uqsort();
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![-1, 0, 1, 3, 7, 11]);
sourcefn modes(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
fn modes(self) -> impl Iterator<Item = (Self::Item, usize)> + Debug
Finds the mode(s) of the iterator’s elements.
§Warning
The results are stored in a HashMap
, which does not preserve the order of the elements.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec![1, 2, 2, 3, 3, 3, 3];
let modes = vec.into_iter().modes().collect::<Vec<_>>();
assert_eq!(modes, vec![(3, 4)]);
sourcefn previous(self, item: Self::Item) -> Previous<Self> ⓘ
fn previous(self, item: Self::Item) -> Previous<Self> ⓘ
The iterator adapter provides the ability to obtain a tuple of two values (last, current) at each iteration.
§Examples
Basic usage:
use iterextd::IterExtd;
let val = 16;
let arr = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let iter = arr.iter().previous(&val).map(|(p, e)| { *p + *e });
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![17, 3, 5, 7, 9, 11, 13, 15, 17, 19]);
sourcefn last_taken(self) -> LastTaken<Self> ⓘwhere
Self: Sized,
fn last_taken(self) -> LastTaken<Self> ⓘwhere
Self: Sized,
An iterator adapter provides the ability to retrieve the last returned value.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let mut iter = arr.into_iter().last_taken();
assert_eq!(Some(1), iter.next());
assert_eq!(Some(&1), iter.last_item());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(&2), iter.last_item());
sourcefn slice_copied<const N: usize>(self) -> SliceCopied<Self, N> ⓘ
fn slice_copied<const N: usize>(self) -> SliceCopied<Self, N> ⓘ
Creates an iterator that copies a slice of all its elements.
§Panics
Panics if the length of the slices is not equal.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = {
let vec = vec![10u8, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222];
let vec_of_slices: [&[u8]; 3] = [&vec[0..3], &vec[3..6], &vec[6..9]];
let iter = vec_of_slices.iter().copied().slice_copied::<3>();
iter.collect::<Vec<_>>()
};
assert_eq!(vec, vec![[10, 11, 22], [33, 44, 55], [66, 77, 88]]);
sourcefn skip_step_by(self, skip: usize, step: usize) -> SkipStepBy<Self> ⓘwhere
Self: Sized,
fn skip_step_by(self, skip: usize, step: usize) -> SkipStepBy<Self> ⓘwhere
Self: Sized,
An iterator adapter with the combined ability to skip and step.
§Panics
The method panics when the specified step is 0.
§Examples
Basic usage:
use iterextd::IterExtd;
let s = "iterator";
let vec = s.chars().skip_step_by(3, 4).collect::<Vec<_>>();
assert_eq!(vec, vec!['r', 'r']);
let v = s.chars().skip(3).step_by(4).collect::<Vec<_>>();
assert_eq!(v, vec!['r', 'r']);
sourcefn step_by_fn<F>(self, f: F) -> StepByFn<Self, F> ⓘ
fn step_by_fn<F>(self, f: F) -> StepByFn<Self, F> ⓘ
The iterator adapter passing through the base iterator uses a closure at each step to change the number of steps.
§Examples
Basic usage:
use iterextd::IterExtd;
let vec = vec![0u32, 11, 22, 33, 44, 55, 66, 77, 88, 99];
let iter = vec.into_iter().step_by_fn(|s| {
if *s == 0 {
*s = 1;
1
} else {
*s += 2;
*s
}
});
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, [0, 33, 88]);
sourcefn to_range_icv(self) -> TupToRangeIcv<Self> ⓘwhere
Self: Sized,
fn to_range_icv(self) -> TupToRangeIcv<Self> ⓘwhere
Self: Sized,
Return an iterator that converts a tuple at each iteration to a RangeInclusive.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [(0, 2), (3, 5), (6, 8),];
let iter = arr.iter().cloned().to_range_icv();
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![0..=2, 3..=5, 6..=8]);
sourcefn to_range(self) -> TupToRange<Self> ⓘwhere
Self: Sized,
fn to_range(self) -> TupToRange<Self> ⓘwhere
Self: Sized,
sourcefn to_tuple(self) -> RangeToTup<Self> ⓘwhere
Self: Sized,
fn to_tuple(self) -> RangeToTup<Self> ⓘwhere
Self: Sized,
sourcefn to_tuple_icv(self) -> RangeIcvToTup<Self> ⓘwhere
Self: Sized,
fn to_tuple_icv(self) -> RangeIcvToTup<Self> ⓘwhere
Self: Sized,
Return an iterator that converts a RangeInclusive at each iteration to a tuple.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [0..=2, 3..=5, 6..=8];
let iter = arr.iter().cloned().to_tuple_icv();
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![(0, 2), (3, 5), (6, 8),]);
sourcefn unique_sorted(self) -> UniqueSorted<Self>
fn unique_sorted(self) -> UniqueSorted<Self>
Return an iterator adapter that yields unique sorted integers.
§Examples
Basic usage:
use iterextd::IterExtd;
let arr = [9u8, 5, 6, 4, 8, 8, 2, 4, 10, 2, 12];
let vec = arr.iter().unique_sorted().collect::<Vec<_>>();
assert_eq!(vec, vec![2, 4, 5, 6, 8, 9, 10, 12]);