orx_iterable/transformations/
mapped.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::Iterable;

/// Wraps an `Iterable` and creates a new `Iterable` which maps the elements of
/// the original iterable.
pub struct Mapped<I, M, U>
where
    I: Iterable,
    M: Fn(I::Item) -> U + Copy,
{
    pub(crate) it: I,
    pub(crate) map: M,
}

impl<I, M, U> Iterable for Mapped<I, M, U>
where
    I: Iterable,
    M: Fn(I::Item) -> U + Copy,
{
    type Item = U;

    type Iter = core::iter::Map<I::Iter, M>;

    fn iter(&self) -> Self::Iter {
        self.it.iter().map(self.map)
    }
}