concision_core/traits/
ops.rs

1/*
2    Appellation: ops <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5/// A trait for applying a function to a type
6pub trait Apply<T, F> {
7    type Output;
8
9    fn apply<U>(&self, f: F) -> Self::Output
10    where
11        F: Fn(T) -> U;
12
13    fn apply_mut<U>(&mut self, f: F) -> Self::Output
14    where
15        F: FnMut(T) -> U;
16}
17
18pub trait ApplyOn<T, F> {
19    type Output;
20
21    fn apply<U>(self, f: F) -> Self::Output
22    where
23        F: FnMut(T) -> U;
24}
25
26pub trait Transform<T> {
27    type Output;
28
29    fn transform(&self, args: &T) -> Self::Output;
30}
31
32/*
33 ************* Implementations *************
34*/
35impl<T, F, S> ApplyOn<T, F> for S
36where
37    S: Iterator<Item = T>,
38{
39    type Output = core::iter::Map<S, F>;
40
41    fn apply<U>(self, f: F) -> Self::Output
42    where
43        F: FnMut(T) -> U,
44    {
45        self.map(f)
46    }
47}