Trait mz_ore::iter::IteratorExt
source · pub trait IteratorExt{
// Provided methods
fn chain_one(self, item: Self::Item) -> Chain<Self, Once<Self::Item>> { ... }
fn all_equal(self) -> bool
where Self::Item: PartialEq { ... }
fn exact_size(self, len: usize) -> ExactSize<Self> ⓘ { ... }
fn repeat_clone<A: Clone>(self, extra_val: A) -> RepeatClone<Self, A> ⓘ { ... }
}
Expand description
Extension methods for iterators.
Provided Methods§
sourcefn chain_one(self, item: Self::Item) -> Chain<Self, Once<Self::Item>>
fn chain_one(self, item: Self::Item) -> Chain<Self, Once<Self::Item>>
Chains a single item
onto the end of this iterator.
Equivalent to self.chain(iter::once(item))
.
sourcefn all_equal(self) -> bool
fn all_equal(self) -> bool
Reports whether all the elements of the iterator are the same.
This condition is trivially true for iterators with zero or one elements.
sourcefn exact_size(self, len: usize) -> ExactSize<Self> ⓘ
fn exact_size(self, len: usize) -> ExactSize<Self> ⓘ
Converts the the iterator into an ExactSizeIterator
reporting the given size.
The caller is responsible for providing the correct size of the iterator! Providing an incorrect size value will lead to panics and/or incorrect responses to size queries.
§Panics
Panics if the given length is not consistent with this iterator’s size_hint
.
sourcefn repeat_clone<A: Clone>(self, extra_val: A) -> RepeatClone<Self, A> ⓘ
fn repeat_clone<A: Clone>(self, extra_val: A) -> RepeatClone<Self, A> ⓘ
Wrap this iterator with one that yields a tuple of the iterator element and the extra
value on each iteration. The extra value is cloned for each but the last Some
element
returned.
This is useful to provide an owned extra value to each iteration, but only clone it when necessary.
NOTE: Once the iterator starts producing None
values, the extra value will be consumed
and no longer be available. This should not be used for iterators that may produce
Some
values after producing None
.