Skip to main content

evaluate_unary_numeric

Function evaluate_unary_numeric 

Source
fn evaluate_unary_numeric(
    arg: &Expr,
    state: &mut EvaluationState,
    traversal_state: &mut StateManager,
    fns: &FunctionMap,
    transform: impl FnOnce(f64) -> f64,
) -> Option<EvaluateResultValue>
Expand description

Helper function to evaluate unary numeric operations (Plus, Minus, Tilde). This reduces code duplication for operations that convert an expression to a number, apply a transformation, and return the result as an expression.

§Arguments

  • arg - The expression argument to the unary operator
  • state - The evaluation state
  • traversal_state - The state manager for traversal context
  • fns - The function map for evaluating function calls
  • transform - A function to transform the numeric value

§Example

UnaryOp::Plus => evaluate_unary_numeric(&arg, state, traversal_state, fns, |v| v),
UnaryOp::Minus => evaluate_unary_numeric(&arg, state, traversal_state, fns, |v| -v),