42
42
<tr>
43
43
<td>Map</td>
44
44
<td>
45
- <code>{ a: 1, b: 2, c: 3} </code>
45
+ <code>{ a: 1, b: 2, c: 3} </code>
46
46
</td>
47
47
</tr>
48
48
<tr>
49
- <td>Nil</t
50
- d>
49
+ <td>Nil</td>
51
50
<td>
52
51
<code>nil</code>
53
52
</td>
116
115
117
116
Examples:
118
117
119
- ``` c++
118
+ ``` expr
120
119
user.Age in 18..45 and user.Name not in ["admin", "root"]
121
120
```
122
121
123
- ``` c++
122
+ ``` expr
124
123
foo matches "^[A-Z].*"
125
124
```
126
125
@@ -143,7 +142,7 @@ The `?.` operator can be used to access a field of a struct or an item of a map
143
142
without checking if the struct or the map is ` nil ` . If the struct or the map is
144
143
` nil ` , the result of the expression is ` nil ` .
145
144
146
- ``` c++
145
+ ``` expr
147
146
author?.User?.Name
148
147
```
149
148
@@ -152,7 +151,7 @@ author?.User?.Name
152
151
The ` ?? ` operator can be used to return the left-hand side if it is not ` nil ` ,
153
152
otherwise the right-hand side is returned.
154
153
155
- ``` c++
154
+ ``` expr
156
155
author?.User?.Name ?? "Anonymous"
157
156
```
158
157
@@ -162,7 +161,7 @@ The slice operator `[:]` can be used to access a slice of an array.
162
161
163
162
For example, variable ` array ` is ` [1, 2, 3, 4, 5] ` :
164
163
165
- ``` c++
164
+ ``` expr
166
165
array[1:4] == [2, 3, 4]
167
166
array[1:-1] == [2, 3, 4]
168
167
array[:3] == [1, 2, 3]
@@ -173,34 +172,12 @@ array[:] == array
173
172
174
173
## Built-in Functions
175
174
176
- <table >
177
- <tr>
178
- <td>
179
- <a href="#allarray-predicate">all()</a><br>
180
- <a href="#anyarray-predicate">any()</a><br>
181
- <a href="#onearray-predicate">one()</a><br>
182
- <a href="#nonearray-predicate">none()</a><br>
183
- </td>
184
- <td>
185
- <a href="#maparray-predicate">map()</a><br>
186
- <a href="#filterarray-predicate">filter()</a><br>
187
- <a href="#countarray-predicate">count()</a><br>
188
- </td>
189
- <td>
190
- <a href="#lenv">len()</a><br>
191
- <a href="#absv">abs()</a><br>
192
- <a href="#intv">int()</a><br>
193
- <a href="#floatv">float()</a><br>
194
- </td>
195
- </tr>
196
- </table >
197
-
198
175
### all(array, predicate)
199
176
200
177
Returns ** true** if all elements satisfies the [ predicate] ( #predicate ) .
201
178
If the array is empty, returns ** true** .
202
179
203
- ``` c++
180
+ ``` expr
204
181
all(Tweets, {.Size < 280})
205
182
```
206
183
@@ -214,7 +191,7 @@ If the array is empty, returns **false**.
214
191
Returns ** true** if _ exactly one_ element satisfies the [ predicate] ( #predicate ) .
215
192
If the array is empty, returns ** false** .
216
193
217
- ```c++
194
+ ``` expr
218
195
one(Participants, {.Winner})
219
196
```
220
197
@@ -237,7 +214,7 @@ Returns new array by filtering elements of the array by [predicate](#predicate).
237
214
Returns the number of elements what satisfies the [ predicate] ( #predicate ) .
238
215
Equivalent to:
239
216
240
- ``` c++
217
+ ``` expr
241
218
len(filter(array, predicate))
242
219
```
243
220
@@ -253,7 +230,7 @@ Returns the absolute value of a number.
253
230
254
231
Returns the integer value of a number or a string.
255
232
256
- ```c++
233
+ ``` expr
257
234
int("123") == 123
258
235
```
259
236
@@ -266,19 +243,19 @@ Returns the float value of a number or a string.
266
243
The predicate is an expression that accepts a single argument. To access
267
244
the argument use the ` # ` symbol.
268
245
269
- ``` c++
246
+ ``` expr
270
247
map(0..9, {# / 2})
271
248
```
272
249
273
250
If items of the array is a struct or a map, it is possible to access fields with
274
251
omitted ` # ` symbol (` #.Value ` becomes ` .Value ` ).
275
252
276
- ```c++
253
+ ``` expr
277
254
filter(Tweets, {len(.Value) > 280})
278
255
```
279
256
280
257
Braces ` { ` ` } ` can be omitted:
281
258
282
- ``` c++
259
+ ``` expr
283
260
filter(Tweets, len(.Value) > 280)
284
261
```
0 commit comments