Skip to main content

transform_map

Function transform_map 

Source
pub fn transform_map<F>(expr: Expression, fun: &F) -> Result<Expression>
Expand description

Transforms an expression tree bottom-up without node removal.

Like transform, but fun returns an Expression directly rather than Option<Expression>, so nodes cannot be deleted. This is a convenience wrapper for the common case where every node is mapped to exactly one output node.

§Example

use polyglot_sql::traversal::transform_map;

// Uppercase all column names in a tree
let result = transform_map(expr, &|e| match e {
    Expression::Column(mut c) => {
        c.name.name = c.name.name.to_uppercase();
        Ok(Expression::Column(c))
    }
    other => Ok(other),
})?;