use crate::expression::*;
impl Expression {
pub fn deep_map(self, f: fn(Self) -> Self) -> Self {
match self {
Expression::Object(ObjectExpression {
id,
logs,
object_type_name,
is_transient,
fields,
}) => f(Expression::Object(ObjectExpression {
id,
logs,
object_type_name,
is_transient,
fields: fields
.into_iter()
.map(|(field_name, expression)| (field_name, expression.deep_map(f)))
.collect(),
})),
Expression::Application(ApplicationExpression {
id,
logs,
function,
arguments,
}) => f(Expression::Application(ApplicationExpression {
id,
logs,
function: function.deep_map(f).into(),
arguments: arguments
.into_iter()
.map(|expression| expression.deep_map(f))
.collect(),
})),
Expression::Function(FunctionExpression {
id,
logs,
body,
parameters,
}) => f(Expression::Function(FunctionExpression {
id,
logs,
body: body.deep_map(f).into(),
parameters,
})),
Expression::Switch(SwitchExpression {
id,
logs,
control,
cases,
default,
}) => f(Expression::Switch(SwitchExpression {
id,
logs,
control: control.deep_map(f).into(),
cases: cases
.into_iter()
.map(|case| SwitchCase {
when: case.when.deep_map(f),
then: case.then.deep_map(f),
})
.collect(),
default: default.deep_map(f).into(),
})),
Expression::Comparison(ComparisonExpression {
id,
logs,
a,
b,
operator,
}) => f(Expression::Comparison(ComparisonExpression {
id,
logs,
a: a.deep_map(f).into(),
b: b.deep_map(f).into(),
operator,
})),
Expression::GetField(GetFieldExpression {
id,
logs,
field_path,
object,
}) => f(Expression::GetField(GetFieldExpression {
id,
logs,
field_path,
object: object.deep_map(f).into(),
})),
Expression::List(ListExpression {
id,
logs,
items,
is_transient,
}) => f(Expression::List(ListExpression {
id,
logs,
is_transient,
items: items
.into_iter()
.map(|expression| expression.deep_map(f))
.collect(),
})),
Expression::Split(SplitExpression {
id,
logs,
split_id,
dimension_id,
expose,
unit_id,
dimension_mapping,
features_mapping,
}) => f(Expression::Split(SplitExpression {
id,
logs,
split_id,
dimension_id,
expose: expose.deep_map(f).into(),
unit_id: unit_id.deep_map(f).into(),
dimension_mapping: match dimension_mapping {
DimensionMapping::Discrete { cases } => DimensionMapping::Discrete {
cases: cases
.into_iter()
.map(|(key, value)| (key, value.deep_map(f)))
.collect(),
},
DimensionMapping::Continuous { function } => DimensionMapping::Continuous {
function: function.deep_map(f).into(),
},
},
features_mapping: features_mapping
.into_iter()
.map(|(feature_id, expression)| (feature_id, expression.deep_map(f)))
.collect(),
})),
Expression::EnumSwitch(EnumSwitchExpression {
id,
logs,
control,
cases,
}) => f(Expression::EnumSwitch(EnumSwitchExpression {
id,
logs,
control: control.deep_map(f).into(),
cases: cases
.into_iter()
.map(|(key, value)| (key, value.deep_map(f)))
.collect(),
})),
Expression::Arithmetic(ArithmeticExpression {
id,
logs,
a,
b,
operator,
}) => f(Expression::Arithmetic(ArithmeticExpression {
id,
logs,
a: a.deep_map(f).into(),
b: b.deep_map(f).into(),
operator,
})),
Expression::LogEvent(LogEventExpression {
id,
logs,
event_type_id,
unit_id,
features_mapping,
}) => f(Expression::LogEvent(LogEventExpression {
id,
logs,
event_type_id,
unit_id: unit_id.deep_map(f).into(),
features_mapping: features_mapping
.into_iter()
.map(|(key, value)| (key, value.deep_map(f)))
.collect(),
})),
Expression::UpdateObject(UpdateObjectExpression {
id,
logs,
object,
updates,
}) => f(Expression::UpdateObject(UpdateObjectExpression {
id,
logs,
object: object.deep_map(f).into(),
updates: updates
.into_iter()
.map(|(field_name, expression)| (field_name, expression.deep_map(f)))
.collect(),
})),
Expression::RoundNumber(RoundNumberExpression { id, logs, number }) => {
f(Expression::RoundNumber(RoundNumberExpression {
id,
logs,
number: number.deep_map(f).into(),
}))
}
Expression::StringifyNumber(StringifyNumberExpression { id, logs, number }) => {
f(Expression::StringifyNumber(StringifyNumberExpression {
id,
logs,
number: number.deep_map(f).into(),
}))
}
Expression::StringConcat(StringConcatExpression { id, logs, strings }) => {
f(Expression::StringConcat(StringConcatExpression {
id,
logs,
strings: strings.deep_map(f).into(),
}))
}
Expression::GetUrlQueryParameter(GetUrlQueryParameterExpression {
id,
logs,
url,
query_parameter_name,
}) => f(Expression::GetUrlQueryParameter(
GetUrlQueryParameterExpression {
id,
logs,
url: url.deep_map(f).into(),
query_parameter_name: query_parameter_name.deep_map(f).into(),
},
)),
Expression::Regex(e) => f(Expression::Regex(e)),
Expression::Boolean(e) => f(Expression::Boolean(e)),
Expression::Variable(e) => f(Expression::Variable(e)),
Expression::Int(e) => f(Expression::Int(e)),
Expression::Float(e) => f(Expression::Float(e)),
Expression::String(e) => f(Expression::String(e)),
Expression::NoOp(e) => f(Expression::NoOp(e)),
Expression::Enum(e) => f(Expression::Enum(e)),
}
}
}