Skip to content

Commit 7fba10a

Browse files
authored
Update Language-Definition.md
1 parent c2b6f32 commit 7fba10a

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

docs/Language-Definition.md

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,71 @@ Example:
133133
user.Age > 30 ? "mature" : "immature"
134134
```
135135

136-
## Builtin functions
136+
## Built-in Functions
137137

138-
* `len` (length of array, map or string)
139-
* `all` (will return `true` if all element satisfies the predicate)
140-
* `none` (will return `true` if all element does NOT satisfy the predicate)
141-
* `any` (will return `true` if any element satisfies the predicate)
142-
* `one` (will return `true` if exactly ONE element satisfies the predicate)
143-
* `filter` (filter array by the predicate)
144-
* `map` (map all items with the closure)
145-
* `count` (returns number of elements what satisfies the predicate)
138+
<table>
139+
<tr>
140+
<td>
141+
<a href="#all">all()</a><br>
142+
<a href="#any">any()</a><br>
143+
<a href="#len">one()</a><br>
144+
<a href="#none">none()</a><br>
145+
</td>
146+
<td>
147+
<a href="#len">len()</a><br>
148+
<a href="#map">map()</a><br>
149+
<a href="#filter">filter()</a><br>
150+
<a href="#count">count()</a><br>
151+
</td>
152+
</tr>
153+
</table>
146154

147-
Examples:
148155

149-
Ensure all tweets are less than 280 chars.
156+
#### `all(array, predicate)`
157+
158+
Returns **true** if all elements satisfies the predicate (or if the array is empty).
150159

151160
```
152161
all(Tweets, {.Size < 280})
153162
```
154163

155-
Ensure there is exactly one winner.
164+
#### `any(array, predicate)`
165+
166+
Returns **true** if any elements satisfies the predicate. If the array is empty, returns **false**.
167+
168+
169+
#### `one(array, predicate)`
170+
171+
Returns **true** if _exactly one_ element satisfies the predicate. If the array is empty, returns **false**.
156172

157173
```
158174
one(Participants, {.Winner})
159175
```
160176

177+
#### `none(array, predicate)`
178+
179+
Returns **true** if _all elements does not_ satisfy the predicate. If the array is empty, returns **true**.
180+
181+
#### `len(v)`
182+
183+
Returns the length of an array, a map or a string.
184+
185+
#### `map(array, closure)`
186+
187+
Returns new array by applying the closure to each element of the array.
188+
189+
#### `filter(array, predicate)`
190+
191+
Returns new array by filtering elements of the array by predicate.
192+
193+
#### `count(array, predicate)`
194+
195+
Returns the number of elements what satisfies the predicate. Equivalent to:
196+
197+
```
198+
len(filter(array, predicate))
199+
```
200+
161201
## Closures
162202

163203
The closure is an expression that accepts a single argument. To access

0 commit comments

Comments
 (0)