33
33
</tr >
34
34
</table >
35
35
36
- ## Supported Literals
36
+ ## Literals
37
37
38
- The package supports:
38
+ * ` true `
39
+ * ` false `
40
+ * ` nil `
39
41
40
- * ** strings** - single and double quotes (e.g. ` "hello" ` , ` 'hello' ` )
41
- * ** numbers** - e.g. ` 103 ` , ` 2.5 ` , ` .5 `
42
- * ** arrays** - e.g. ` [1, 2, 3] `
43
- * ** maps** - e.g. ` {foo: "bar"} `
44
- * ** booleans** - ` true ` and ` false `
45
- * ** nil** - ` nil `
42
+ ### Strings
46
43
47
- ## Digit separators
44
+ Single or double quotes. Unicode sequences ( ` \uXXXX ` ) are supported.
48
45
49
- Integer literals may contain digit separators to allow digit grouping into more
50
- legible forms.
46
+ ### Numbers
51
47
52
- Example:
48
+ Integers and floats.
53
49
54
- ``` js
55
- 10_000_000_000
56
- ```
50
+ * ` 42 `
51
+ * ` 3.14 `
52
+ * ` 1e6 `
53
+ * ` 0x2A `
54
+ * ` 1_000_000 `
57
55
58
- ## Fields
56
+ ### Arrays
59
57
60
- Struct fields and map elements can be accessed by using the ` . ` or the ` [] `
61
- syntax.
58
+ * ` [1, 2, 3] `
62
59
63
- ``` js
64
- foo .Field
65
- bar[" some-key" ]
66
- ```
60
+ Tailing commas are allowed.
67
61
68
- ## Functions
62
+ ### Maps
69
63
70
- Functions may be called using the ` () ` syntax.
64
+ * ` {foo: "bar"} `
71
65
72
- ``` js
73
- foo .Method ()
74
- ```
66
+ Tailing commas are allowed.
75
67
76
68
## Operators
77
69
@@ -86,7 +78,7 @@ foo.Method()
86
78
87
79
Example:
88
80
89
- ``` js
81
+ ```
90
82
x^2 + y^2
91
83
```
92
84
@@ -107,7 +99,7 @@ x^2 + y^2
107
99
108
100
Example:
109
101
110
- ``` js
102
+ ```
111
103
life < universe || life < everything
112
104
```
113
105
@@ -121,23 +113,27 @@ life < universe || life < everything
121
113
122
114
Example:
123
115
124
- ``` js
116
+ ```
125
117
"hello" matches "h.*"
126
118
```
127
119
128
120
### Membership Operators
129
121
122
+ * ` . ` (dot)
130
123
* ` in ` (contain)
131
124
* ` not in ` (does not contain)
132
125
126
+ Struct fields and map elements can be accessed by using the ` . ` or the ` [] `
127
+ syntax.
128
+
133
129
Example:
134
130
135
- ``` js
131
+ ```
136
132
user.Group in ["human_resources", "marketing"]
137
133
```
138
134
139
- ``` js
140
- " foo " in {foo: 1 , bar: 2 }
135
+ ```
136
+ data["tag-name"] in {foo: 1, bar: 2}
141
137
```
142
138
143
139
### Range Operator
@@ -146,13 +142,13 @@ user.Group in ["human_resources", "marketing"]
146
142
147
143
Example:
148
144
149
- ``` js
145
+ ```
150
146
user.Age in 18..45
151
147
```
152
148
153
149
The range is inclusive:
154
150
155
- ``` js
151
+ ```
156
152
1..3 == [1, 2, 3]
157
153
```
158
154
@@ -166,7 +162,7 @@ Example:
166
162
167
163
Variable ` array ` is ` [1,2,3,4,5] ` .
168
164
169
- ``` js
165
+ ```
170
166
array[1:4] == [2,3,4]
171
167
array[:3] == [1,2,3]
172
168
array[3:] == [4,5]
@@ -179,7 +175,7 @@ array[:] == array
179
175
180
176
Example:
181
177
182
- ``` js
178
+ ```
183
179
user.Age > 30 ? "mature" : "immature"
184
180
```
185
181
@@ -190,7 +186,7 @@ user.Age > 30 ? "mature" : "immature"
190
186
Returns ** true** if all elements satisfies the [ predicate] ( #predicate ) .
191
187
If the array is empty, returns ** true** .
192
188
193
- ``` js
189
+ ```
194
190
all(Tweets, {.Size < 280})
195
191
```
196
192
@@ -199,13 +195,12 @@ all(Tweets, {.Size < 280})
199
195
Returns ** true** if any elements satisfies the [ predicate] ( #predicate ) .
200
196
If the array is empty, returns ** false** .
201
197
202
-
203
198
### ` one(array, predicate) `
204
199
205
200
Returns ** true** if _ exactly one_ element satisfies the [ predicate] ( #predicate ) .
206
201
If the array is empty, returns ** false** .
207
202
208
- ``` js
203
+ ```
209
204
one(Participants, {.Winner})
210
205
```
211
206
@@ -232,22 +227,22 @@ Returns new array by filtering elements of the array by [predicate](#predicate).
232
227
Returns the number of elements what satisfies the [ predicate] ( #predicate ) .
233
228
Equivalent to:
234
229
235
- ``` js
230
+ ```
236
231
len(filter(array, predicate))
237
232
```
238
233
239
234
## Predicate
240
235
241
- The predicate is an expression that accepts a single argument. To access
236
+ The predicate is an expression that accepts a single argument. To access
242
237
the argument use the ` # ` symbol.
243
238
244
- ``` js
239
+ ```
245
240
map(0..9, {# / 2})
246
241
```
247
242
248
- If items of the array is a struct or a map, it is possible to access fields with
243
+ If items of the array is a struct or a map, it is possible to access fields with
249
244
omitted ` # ` symbol (` #.Value ` becomes ` .Value ` ).
250
245
251
- ``` js
246
+ ```
252
247
filter(Tweets, {len(.Value) > 280})
253
248
```
0 commit comments