1use core::iter;
4
5use crate::non_empty::NonEmptyIterator;
6
7#[derive(Debug, Clone)]
14#[must_use = "non-empty iterators are lazy and do nothing unless consumed"]
15pub struct Map<I: NonEmptyIterator, F> {
16 non_empty: I,
17 function: F,
18}
19
20impl<I: NonEmptyIterator, F> Map<I, F> {
21 pub const fn new(non_empty: I, function: F) -> Self {
23 Self {
24 non_empty,
25 function,
26 }
27 }
28}
29
30impl<U, I: NonEmptyIterator, F: FnMut(I::Item) -> U> IntoIterator for Map<I, F> {
31 type Item = U;
32
33 type IntoIter = iter::Map<I::IntoIter, F>;
34
35 fn into_iter(self) -> Self::IntoIter {
36 self.non_empty.into_iter().map(self.function)
37 }
38}
39
40unsafe impl<U, I: NonEmptyIterator, F: FnMut(I::Item) -> U> NonEmptyIterator for Map<I, F> {}