1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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)),
        }
    }
}