Skip to content

Commit 92c9068

Browse files
committed
Update Language-Definition.md
1 parent 999485d commit 92c9068

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

docs/Language-Definition.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ user.Age in 18..45 and user.Name not in ["admin", "root"]
128128
foo matches "^[A-Z].*"
129129
```
130130

131+
```expr
132+
tweets | filter(.Size < 280) | map(.Content) | join(" -- ")
133+
```
134+
135+
```expr
136+
filter(posts, {now() - .CreatedAt >= 7 * duration("24h")})
137+
```
138+
131139
### Membership Operator
132140

133141
Fields of structs and items of maps can be accessed with `.` operator
@@ -185,6 +193,16 @@ For example, expression `split(lower(user.Name), " ")` can be written as:
185193
user.Name | lower() | split(" ")
186194
```
187195

196+
### Date Manipulation
197+
198+
The following operators can be used to manipulate dates:
199+
200+
```expr
201+
date("2023-08-14") + duration("1h")
202+
date("2023-08-14") - duration("1h")
203+
date("2023-08-14") - date("2023-08-13") == duration("24h")
204+
```
205+
188206
## Built-in Functions
189207

190208
### all(array, predicate)
@@ -193,7 +211,7 @@ Returns **true** if all elements satisfies the [predicate](#predicate).
193211
If the array is empty, returns **true**.
194212

195213
```expr
196-
all(Tweets, {.Size < 280})
214+
all(tweets, {.Size < 280})
197215
```
198216

199217
### any(array, predicate)
@@ -207,7 +225,7 @@ Returns **true** if _exactly one_ element satisfies the [predicate](#predicate).
207225
If the array is empty, returns **false**.
208226

209227
```expr
210-
one(Participants, {.Winner})
228+
one(participants, {.Winner})
211229
```
212230

213231
### none(array, predicate)
@@ -221,7 +239,7 @@ Returns new array by applying the [predicate](#predicate) to each element of
221239
the array.
222240

223241
```expr
224-
map(Tweets, {.Size})
242+
map(tweets, {.Size})
225243
```
226244

227245
### filter(array, predicate)
@@ -673,19 +691,20 @@ If items of the array is a struct or a map, it is possible to access fields with
673691
omitted `#` symbol (`#.Value` becomes `.Value`).
674692

675693
```expr
676-
filter(Tweets, {len(.Value) > 280})
694+
filter(tweets, {len(.Value) > 280})
677695
```
678696

679697
Braces `{` `}` can be omitted:
680698

681699
```expr
682-
filter(Tweets, len(.Value) > 280)
700+
filter(tweets, len(.Value) > 280)
683701
```
684702

685703
## `$env` variable
686704

687705
The `$env` variable is a map of all variables passed to the expression.
688706

689707
```expr
690-
Foo.Name == $env["Foo"].Name
708+
foo.Name == $env["foo"].Name
709+
$env["var with spaces"]
691710
```

0 commit comments

Comments
 (0)