concepts.dm.crow.function_utils.flatten_expression#
- flatten_expression(expr, mappings=None, ctx=None, flatten_cacheable_expression=True)[source]#
- Flatten an expression by replacing certain variables or function applications with sub-expressions. The input mapping is a dictionary of {expression: sub-expression}. There are two cases: - The expression is a VariableExpression, and the sub-expression is a
- Variableor a- ValueOutputExpression. In this case, the variable expression will is the sub-expression used for replacing the variable.
 
- The expression is a 
- The expression is a FunctionApplicationExpression, and the sub-expression is a
- Variable. Here, the function application expression must be a “simple” function application expression, i.e., it contains only variables as arguments. The Variable will replace the entire function application expression.
 
- The expression is a 
 - Parameters:
- expr (Expression) – the expression to flatten. 
- mappings (Dict[FunctionApplicationExpression | VariableExpression, Variable | ValueOutputExpression] | None) – a dictionary of {expression: sub-expression} to replace the expression with the sub-expression. 
- ctx (ExpressionDefinitionContext | None) – a - ExpressionDefinitionContext.
- flatten_cacheable_expression (bool) – whether to flatten cacheable expressions. If False, cacheable function applications will be kept as-is. 
 
- Returns:
- the flattened expression. 
- Return type:
- ObjectOrValueOutputExpression | VariableAssignmentExpression