You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,7 @@ Indexes are zero-based. Slice indexes are optional and are _inclusive_. `foo[1:2
187
187
188
188
#### Array/slice filtering
189
189
190
-
A `where` clause can be used to filter the items in an array. The left side of the clause is the array to be filtered, while the right side is an expression to run on each item of the array. If the right side expression evaluates to true then the item is added to the result. For example:
190
+
A `where` clause can be used to filter the items in an array. The left side of the clause is the array to be filtered, while the right side is an expression to run on each item of the array. If the right side expression evaluates to true then the item is added to the result slice. For example:
191
191
192
192
```
193
193
// Get a list of items where the item.id is bigger than 3
@@ -221,6 +221,33 @@ not (items where id > 3)
221
221
-`in` (has key), e.g. `"key" in foo`
222
222
-`contains` e.g. `foo contains "key"`
223
223
224
+
#### Map wildcard filtering
225
+
226
+
A `where` clause can be used as a wildcard key to filter values for all keys in a map. The left side of the clause is the map to be filtered, while the right side is an expression to run on each value of the map. If the right side expression evaluates to true then the value is added to the result slice. For example, given:
227
+
228
+
```json
229
+
{
230
+
"operations": {
231
+
"id1": { "method": "GET", "path": "/op1" },
232
+
"id2": { "method": "PUT", "path": "/op2" },
233
+
"id3": { "method": "DELETE", "path": "/op3" }
234
+
}
235
+
}
236
+
```
237
+
238
+
You can run:
239
+
240
+
```
241
+
// Get all operations where the HTTP method is GET
242
+
operations where method == "GET"
243
+
```
244
+
245
+
And the result would be a slice of matched values:
246
+
247
+
```json
248
+
[{ "method": "GET", "path": "/op1" }]
249
+
```
250
+
224
251
## Performance
225
252
226
253
Performance compares favorably to [antonmedv/expr](https://github.com/antonmedv/expr) for both `Eval(...)` and cached program performance, which is expected given the more limited feature set. The `slow` benchmarks include lexing/parsing/interpreting while the `cached` ones are just the interpreting step. The `complex` example expression used is non-trivial: `foo.bar / (1 * 1024 * 1024) >= 1.0 and "v" in baz and baz.length > 3 and arr[2:].length == 1`.
0 commit comments