/// Make a [`RecExpr`] by mapping this enodes children to other [`RecExpr`]s.
///
/// This can be used to join together different expression with a new node.
///
/// # Example
/// ```
/// # use egg::*;
/// let a_plus_2: RecExpr<SymbolLang> = "(+ a 2)".parse().unwrap();
/// // here's an enode with some meaningless child ids
/// let enode = SymbolLang::new("*", vec![Id::from(0), Id::from(0)]);
/// // make a new recexpr, replacing enode's children with a_plus_2
/// let recexpr = enode.join_recexprs(|_id| &a_plus_2);
/// assert_eq!(recexpr, "(* (+ a 2) (+ a 2))".parse().unwrap())
/// ```
Make a [`RecExpr`] by mapping this enodes children to other [`RecExpr`]s.
This can be used to join together different expression with a new node.
Make a [ ` RecExpr ` ] by mapping this enodes children to other [ ` RecExpr ` ] s . This can be used to join together different expression with a new node .
fn join_recexprs<F, Expr>(&self, mut child_recexpr: F) -> RecExpr<Self>
    where
        F: FnMut(Id) -> Expr,
        Expr: AsRef<[Self]>,
    {
        fn build<L: Language>(to: &mut RecExpr<L>, from: &[L]) -> Id {
            let last = from.last().unwrap().clone();
            let new_node = last.map_children(|id| {
                let i = usize::from(id) + 1;
                build(to, &from[0..i])
            });
            to.add(new_node)
        }
        let mut expr = RecExpr::default();
        let node = self
            .clone()
            .map_children(|id| build(&mut expr, child_recexpr(id).as_ref()));
        expr.add(node);
        expr
    }
fn join_recexprs < F , Expr > ( & self , mut child_recexpr : F ) -> RecExpr < Self > where F : FnMut ( Id ) -> Expr , Expr : AsRef < [ Self ] > , { fn build < L : Language > ( to : & mut RecExpr < L > , from : & [ L ] ) -> Id { let last = from . last ( ) . unwrap ( ) . clone ( ) ; let new_node = last . map_children ( | id | { let i = usize :: from ( id ) + 1 ; build ( to , & from [ 0 .. i ] ) } ) ; to . add ( new_node ) } let mut expr = RecExpr :: default ( ) ; let node = self . clone ( ) . map_children ( | id | build ( & mut expr , child_recexpr ( id ) . as_ref ( ) ) ) ; expr . add ( node ) ; expr }
Make a [`RecExpr`] by mapping this enodes children to other [`RecExpr`]s.
This can be used to join together different expression with a new node.
Make a [ ` RecExpr ` ] by mapping this enodes children to other [ ` RecExpr ` ] s . This can be used to join together different expression with a new node .
&self
child_recexpr
F
example
None
use egg::*;
let a_plus_2: RecExpr = "(+ a 2)".parse().unwrap();
here's an enode with some meaningless child ids
let enode = SymbolLang::new("*", vec![Id::from(0), Id::from(0)]);
make a new recexpr, replacing enode's children with a_plus_2
let recexpr = enode.join_recexprs(|_id| &a_plus_2);
assert_eq!(recexpr, "(* (+ a 2) (+ a 2))".parse().unwrap())
```
let a_plus_2 : RecExpr = " ( + a 2 ) " . parse () . unwrap () ; here ' s an enode with some meaningless child ids let enode = SymbolLang :: new ( " * " vec! [ Id :: from ( 0 ) Id :: from ( 0 ) ] ) ; make a new recexpr replacing enode ' s children with a_plus_2 let recexpr = enode . join_recexprs ( |_id| &a_plus_2 ) ; assert_eq! ( recexpr " ( * ( + a 2 ) ( + a 2 )) " . parse () . unwrap () ) ` ` `