ArrayNonEmptyIterator

Struct ArrayNonEmptyIterator 

Source
pub struct ArrayNonEmptyIterator<T, const C: usize> { /* private fields */ }
Expand description

Non-empty iterator for arrays with length > 0.

§Examples

Use non-zero length arrays anywhere an IntoNonEmptyIterator is expected.

use std::num::NonZeroUsize;

use nonempty_collections::*;

fn is_one<T>(iter: impl IntoNonEmptyIterator<Item = T>) {
    assert_eq!(NonZeroUsize::MIN, iter.into_nonempty_iter().count());
}

is_one([0]);

Only compiles for non-empty arrays:

use nonempty_collections::*;

fn is_one(iter: impl IntoNonEmptyIterator<Item = usize>) {}

is_one([]); // Doesn't compile because it is empty.

Trait Implementations§

Source§

impl<T: Clone, const C: usize> Clone for ArrayNonEmptyIterator<T, C>

Source§

fn clone(&self) -> ArrayNonEmptyIterator<T, C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const C: usize> Debug for ArrayNonEmptyIterator<T, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const C: usize> IntoIterator for ArrayNonEmptyIterator<T, C>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, C>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, const C: usize> NonEmptyIterator for ArrayNonEmptyIterator<T, C>

Source§

fn next(self) -> (Self::Item, Self::IntoIter)
where Self: Sized,

Advances this non-empty iterator, consuming its ownership. Yields the first item and a possibly empty iterator containing the rest of the elements.
Source§

fn peekable(self) -> Peekable<Self::IntoIter>
where Self: Sized,

Creates an iterator which can use the peek and peek_mut methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more
Source§

fn all<F>(self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if every element of the iterator matches a predicate. Read more
Source§

fn any<F>(self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if any element of the iterator matches a predicate. Read more
Source§

fn chain<U>(self, other: U) -> Chain<Self::IntoIter, U::IntoIter>
where Self: Sized, U: IntoIterator<Item = Self::Item>,

Takes two iterators and creates a new non-empty iterator over both in sequence. Read more
Source§

fn cloned<'a, T>(self) -> Cloned<Self>
where Self: Sized + NonEmptyIterator<Item = &'a T>, T: Clone + 'a,

Creates a non-empty iterator which clones all of its elements. Read more
Source§

fn collect<B>(self) -> B
where Self: Sized, B: FromNonEmptyIterator<Self::Item>,

Transforms an iterator into a collection, or some other concrete value. Read more
Source§

fn copied<'a, T>(self) -> Copied<Self::IntoIter>
where Self: Sized + NonEmptyIterator<Item = &'a T>, T: Copy + 'a,

Creates a non-empty iterator which copies all of its elements. Read more
Source§

fn count(self) -> NonZeroUsize
where Self: Sized,

Consumes the non-empty iterator, counting the number of iterations and returning it. Read more
Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates a non-empty iterator which gives the current iteration count as well as the next value. Read more
Source§

fn filter<P>(self, predicate: P) -> Filter<<Self as IntoIterator>::IntoIter, P>
where Self: Sized, P: FnMut(&<Self as IntoIterator>::Item) -> bool,

Creates an iterator which uses a closure to determine if an element should be yielded. Read more
Source§

fn filter_map<B, F>( self, f: F, ) -> FilterMap<<Self as IntoIterator>::IntoIter, F>
where Self: Sized, F: FnMut(<Self as IntoIterator>::Item) -> Option<B>,

Creates an iterator that both filters and maps. Read more
Source§

fn find<P>(self, predicate: P) -> Option<Self::Item>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Searches for an element of an iterator that satisfies a predicate. Read more
Source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self::IntoIter, U, F>
where Self: Sized, F: FnMut(Self::Item) -> U, U: IntoNonEmptyIterator,

Creates an iterator that works like map, but flattens nested, non-empty structure. Read more
Source§

fn fold<B, F>(self, init: B, f: F) -> B
where Self: Sized, F: FnMut(B, Self::Item) -> B,

Folds every element into an accumulator by applying an operation, returning the final result. Read more
Source§

fn group_by<K, F>(self, f: F) -> NEGroupBy<Self, F>
where Self: Sized, F: FnMut(&Self::Item) -> K, K: PartialEq,

Group the non-empty input stream into concrete, non-empty subsections via a given function. The cutoff criterion is whether the return value of f changes between two consecutive elements. Read more
Source§

fn map<U, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> U,

Takes a closure and creates a non-empty iterator which calls that closure on each element. Read more
Source§

fn max(self) -> Self::Item
where Self: Sized, Self::Item: Ord,

Returns the maximum element of a non-empty iterator. Read more
Source§

fn max_by<F>(self, compare: F) -> Self::Item
where Self: Sized, F: Fn(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the maximum value with respect to the given comparison function. Read more
Source§

fn max_by_key<B, F>(self, key: F) -> Self::Item
where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> B,

Returns the element that gives the maximum value from the specified function. Read more
Source§

fn min(self) -> Self::Item
where Self: Sized, Self::Item: Ord,

Returns the minimum element of a non-empty iterator. Read more
Source§

fn min_by<F>(self, compare: F) -> Self::Item
where Self: Sized, F: Fn(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the minimum value with respect to the given comparison function. Read more
Source§

fn min_by_key<B, F>(self, key: F) -> Self::Item
where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> B,

Returns the element that gives the minimum value from the specified function. Read more
Source§

fn sorted_by_key<K, F>(self, f: F) -> IntoIter<Self::Item>
where Self: Sized, K: Ord, F: FnMut(&Self::Item) -> K,

Sort all iterator elements into a new non-empty iterator in ascending order. Read more
Source§

fn nth(self, n: usize) -> Option<Self::Item>
where Self: Sized,

Returns the nth element of the iterator. Read more
Source§

fn skip(self, n: usize) -> Skip<<Self as IntoIterator>::IntoIter>
where Self: Sized,

Skip the first n elements. Read more
Source§

fn skip_while<P>( self, pred: P, ) -> SkipWhile<<Self as IntoIterator>::IntoIter, P>
where Self: Sized, P: FnMut(&<Self as IntoIterator>::Item) -> bool,

Skips over all initial elements that pass a given predicate. Read more
Source§

fn sum<S>(self) -> S
where Self: Sized + IntoIterator, S: Sum<<Self as IntoIterator>::Item>,

Sums the elements of a non-empty iterator. Read more
Source§

fn take(self, n: NonZeroUsize) -> Take<Self>
where Self: Sized,

Iterates over the first n elements, or fewer if the underlying iterator ends sooner. Read more
Source§

fn take_while<P>( self, pred: P, ) -> TakeWhile<<Self as IntoIterator>::IntoIter, P>
where Self: Sized, P: FnMut(&<Self as IntoIterator>::Item) -> bool,

Iterates over all initial elements that pass a given predicate. Read more
Source§

fn product<P>(self) -> P
where Self: Sized + IntoIterator, P: Product<<Self as IntoIterator>::Item>,

Iterates over the entire non-empty iterator, multiplying all the elements. Read more
Source§

fn zip<U>(self, other: U) -> Zip<Self::IntoIter, U::IntoIter>
where Self: Sized, U: IntoNonEmptyIterator,

“Zips up” two non-empty iterators into a single one, while preserving non-emptiness. Read more
Source§

fn reduce<F>(self, f: F) -> Self::Item
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more

Auto Trait Implementations§

§

impl<T, const C: usize> Freeze for ArrayNonEmptyIterator<T, C>
where T: Freeze,

§

impl<T, const C: usize> RefUnwindSafe for ArrayNonEmptyIterator<T, C>
where T: RefUnwindSafe,

§

impl<T, const C: usize> Send for ArrayNonEmptyIterator<T, C>
where T: Send,

§

impl<T, const C: usize> Sync for ArrayNonEmptyIterator<T, C>
where T: Sync,

§

impl<T, const C: usize> Unpin for ArrayNonEmptyIterator<T, C>
where T: Unpin,

§

impl<T, const C: usize> UnwindSafe for ArrayNonEmptyIterator<T, C>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoIteratorExt for T
where T: IntoIterator,

Source§

fn try_into_nonempty_iter(self) -> Option<<T as IntoIteratorExt>::IntoIter>

Converts self into a non-empty iterator or returns None if the iterator is empty.

Source§

type Item = <T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = NonEmptyIterAdapter<Peekable<<T as IntoIterator>::IntoIter>>

Which kind of NonEmptyIterator are we turning this into?
Source§

impl<I> IntoNonEmptyIterator for I

Source§

type IntoNEIter = I

Which kind of NonEmptyIterator are we turning this into?
Source§

fn into_nonempty_iter(self) -> <I as IntoNonEmptyIterator>::IntoNEIter

Creates a NonEmptyIterator from a value.
Source§

impl<T> NonEmptyItertools for T
where T: NonEmptyIterator + ?Sized,

Source§

fn cartesian_product<J>(self, other: J) -> Product<Self, J::IntoNEIter>

Return a non-empty iterator adaptor that iterates over the non-empty cartesian product of the element sets of two iterators self and J. Read more
Source§

fn all_unique(self) -> bool
where Self: Sized, Self::Item: Eq + Hash,

Check whether all elements are unique (non equal). Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.