Skip to content

Commit

Permalink
docs: added few methods on list/map
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jun 24, 2024
1 parent 0cac7f1 commit da530fa
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions canary-checker/docs/scripting/cel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,124 @@ base64.decode("aGVsbG8=") // return b'hello'
## collections
### .keys
The `keys` method on a map returns a list of keys..
Syntax:
```javascript
e.keys()
// Where:
// `e` is a map .
```
Examples:
```javascript
{"first": "John", "last": "Doe"}.keys() // ["first", "last"]
```
### .merge
The `merge` method on a map takes in a second map to merge with.
Syntax:
```javascript
e.merge(x)
// Where:
// `e` is the map you want to merge to.
// `x` is the second map to merge from.
```
Examples:
```javascript
{"first": "John"}.merge({"last": "Doe"}) // {"first": "John", "last": "Doe"}
```
### .omit
The `omit` method on a map takes a list of keys to omit from the map.
Syntax:
```javascript
e.omit(x)
// Where:
// `e` is a list .
// `x` is a list of keys to omit.
```
Examples:
```javascript
{"first": "John", "last": "Doe"}.omit(["first"]) // {"last": "Doe"}
```
### .sort
The `sort` method on a list returns the reversed list.
Syntax:
```javascript
e.sort()
// Where:
// `e` is a list .
```
Examples:
```javascript
[3, 2, 1].sort() // [1, 2, 3]
['c', 'b', 'a'].sort() // ['a', 'b', 'c']
```
### .uniq
The `uniq` method on a list returns a list of the unique elements.
Syntax:
```javascript
e.uniq()
// Where:
// `e` is a list .
```
Examples:
```javascript
[1,2,3,3,3,].uniq().sum() // 10
["a", "b", "b"].uniq().join() // "ab"
```
### .values
The `values` method on a map returns a list of values.
Syntax:
```javascript
e.values()
// Where:
// `e` is a map .
```
Examples:
```javascript
{'a': 1, 'b': 2}.values().sum() // 3
```
### all
The `all` macro tests whether a predicate holds for **all** elements of a list `e` or keys of a map `e`. It returns a boolean value based on the evaluation.
Expand Down

0 comments on commit da530fa

Please sign in to comment.