Skip to content

Commit da530fa

Browse files
committed
docs: added few methods on list/map
1 parent 0cac7f1 commit da530fa

File tree

1 file changed

+118
-0
lines changed
  • canary-checker/docs/scripting

1 file changed

+118
-0
lines changed

canary-checker/docs/scripting/cel.mdx

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,124 @@ base64.decode("aGVsbG8=") // return b'hello'
110110
111111
## collections
112112
113+
### .keys
114+
115+
The `keys` method on a map returns a list of keys..
116+
117+
Syntax:
118+
119+
```javascript
120+
e.keys()
121+
122+
// Where:
123+
// `e` is a map .
124+
```
125+
126+
Examples:
127+
128+
```javascript
129+
{"first": "John", "last": "Doe"}.keys() // ["first", "last"]
130+
```
131+
132+
### .merge
133+
134+
The `merge` method on a map takes in a second map to merge with.
135+
136+
Syntax:
137+
138+
```javascript
139+
e.merge(x)
140+
141+
// Where:
142+
// `e` is the map you want to merge to.
143+
// `x` is the second map to merge from.
144+
```
145+
146+
Examples:
147+
148+
```javascript
149+
{"first": "John"}.merge({"last": "Doe"}) // {"first": "John", "last": "Doe"}
150+
```
151+
152+
### .omit
153+
154+
The `omit` method on a map takes a list of keys to omit from the map.
155+
156+
Syntax:
157+
158+
```javascript
159+
e.omit(x)
160+
161+
// Where:
162+
// `e` is a list .
163+
// `x` is a list of keys to omit.
164+
```
165+
166+
Examples:
167+
168+
```javascript
169+
{"first": "John", "last": "Doe"}.omit(["first"]) // {"last": "Doe"}
170+
```
171+
172+
### .sort
173+
174+
The `sort` method on a list returns the reversed list.
175+
176+
Syntax:
177+
178+
```javascript
179+
e.sort()
180+
181+
// Where:
182+
// `e` is a list .
183+
```
184+
185+
Examples:
186+
187+
```javascript
188+
[3, 2, 1].sort() // [1, 2, 3]
189+
['c', 'b', 'a'].sort() // ['a', 'b', 'c']
190+
```
191+
192+
### .uniq
193+
194+
The `uniq` method on a list returns a list of the unique elements.
195+
196+
Syntax:
197+
198+
```javascript
199+
e.uniq()
200+
201+
// Where:
202+
// `e` is a list .
203+
```
204+
205+
Examples:
206+
207+
```javascript
208+
[1,2,3,3,3,].uniq().sum() // 10
209+
["a", "b", "b"].uniq().join() // "ab"
210+
```
211+
212+
### .values
213+
214+
The `values` method on a map returns a list of values.
215+
216+
Syntax:
217+
218+
```javascript
219+
e.values()
220+
221+
// Where:
222+
// `e` is a map .
223+
```
224+
225+
Examples:
226+
227+
```javascript
228+
{'a': 1, 'b': 2}.values().sum() // 3
229+
```
230+
113231
### all
114232
115233
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.

0 commit comments

Comments
 (0)