1
use crate::Commands;
2
use uniplate::Uniplate;
3

            
4
pub struct Reduction<T, M>
5
where
6
    T: Uniplate,
7
{
8
    pub new_tree: T,
9
    pub(crate) commands: Commands<T, M>,
10
}
11

            
12
impl<T, M> Reduction<T, M>
13
where
14
    T: Uniplate,
15
{
16
247
    pub(crate) fn apply_transform<F>(transform: F, tree: &T, meta: &M) -> Option<Self>
17
247
    where
18
247
        F: Fn(&mut Commands<T, M>, &T, &M) -> Option<T>,
19
247
    {
20
247
        let mut commands = Commands::new();
21
247
        let new_tree = transform(&mut commands, &tree, &meta)?;
22
37
        Some(Self { new_tree, commands })
23
247
    }
24
}