use core::iter;
use crate::non_empty::NonEmptyIterator;
#[derive(Debug, Clone)]
#[must_use = "non-empty iterators are lazy and do nothing unless consumed"]
pub struct Map<I: NonEmptyIterator, F> {
non_empty: I,
function: F,
}
impl<I: NonEmptyIterator, F> Map<I, F> {
pub const fn new(non_empty: I, function: F) -> Self {
Self {
non_empty,
function,
}
}
}
impl<U, I: NonEmptyIterator, F: FnMut(I::Item) -> U> IntoIterator for Map<I, F> {
type Item = U;
type IntoIter = iter::Map<I::IntoIter, F>;
fn into_iter(self) -> Self::IntoIter {
self.non_empty.into_iter().map(self.function)
}
}
unsafe impl<U, I: NonEmptyIterator, F: FnMut(I::Item) -> U> NonEmptyIterator for Map<I, F> {}