indicator/gat/operator/map.rs
1use super::GatOperator;
2
3/// Operator returns by [`map`].
4#[derive(Debug, Clone, Copy)]
5pub struct Map<F>(pub(super) F);
6
7/// Convert the input directly.
8/// ```
9/// use indicator::gat::*;
10///
11/// fn plus_one() -> impl for<'out> GatOperator<usize, Output<'out> = usize> {
12/// map(|x| x + 1)
13/// }
14/// ```
15pub fn map<I, O, F>(f: F) -> Map<F>
16where
17 F: FnMut(I) -> O,
18{
19 Map(f)
20}
21
22impl<I, O, F> GatOperator<I> for Map<F>
23where
24 F: FnMut(I) -> O,
25{
26 type Output<'out> = O where F: 'out, I: 'out;
27
28 #[inline]
29 fn next<'out>(&'out mut self, input: I) -> Self::Output<'out>
30 where
31 I: 'out,
32 {
33 (self.0)(input)
34 }
35}