@@ -4,7 +4,7 @@ description: Describes the lambda functions to use in a Bicep file.
4
4
author : mumian
5
5
ms.topic : conceptual
6
6
ms.author : jgao
7
- ms.date : 09/15 /2022
7
+ ms.date : 09/20 /2022
8
8
9
9
---
10
10
# Lambda functions for Bicep
@@ -46,9 +46,9 @@ Namespace: [sys](bicep-functions.md#namespaces-for-functions).
46
46
47
47
An array.
48
48
49
- ### Example
49
+ ### Examples
50
50
51
- The following example shows how to use the filter function.
51
+ The following examples show how to use the filter function.
52
52
53
53
``` bicep
54
54
var dogs = [
@@ -73,21 +73,31 @@ var dogs = [
73
73
interests: ['Rubs']
74
74
}
75
75
]
76
+
77
+ output oldDogs array = filter(dogs, dog => dog.age >=5)
78
+ ```
79
+
80
+ The output from the preceding example shows the dogs that are five or older:
81
+
82
+ | Name | Type | Value |
83
+ | ---- | ---- | ----- |
84
+ | oldDogs | Array | [ {"name":"Evie","age":5,"interests":[ "Ball","Frisbee"] },{"name":"Kira","age":8,"interests":[ "Rubs"] }] |
85
+
86
+ ``` bicep
76
87
var itemForLoop = [for item in range(0, 10): item]
77
88
78
89
output filteredLoop array = filter(itemForLoop, i => i > 5)
79
90
output isEven array = filter(range(0, 10), i => 0 == i % 2)
80
-
81
- output oldDogs array = filter(dogs, dog => dog.age >=5)
82
91
```
83
92
84
- The output from the preceding example shows the dogs that are five or older :
93
+ The output from the preceding example:
85
94
86
95
| Name | Type | Value |
87
96
| ---- | ---- | ----- |
88
97
| filteredLoop | Array | [ 6, 7, 8, 9] |
89
98
| isEven | Array | [ 0, 2, 4, 6, 8] |
90
- | oldDogs | Array | [ {"name":"Evie","age":5,"interests":[ "Ball","Frisbee"] },{"name":"Kira","age":8,"interests":[ "Rubs"] }] |
99
+
100
+ ** filterdLoop** shows the numbers in an array that are greater than 5; and ** isEven** shows the even numbers in the array.
91
101
92
102
## map
93
103
@@ -153,6 +163,8 @@ The output from the preceding example is:
153
163
| sayHi | Array | [ "Hello Evie!","Hello Casper!","Hello Indy!","Hello Kira!"] |
154
164
| mapObject | Array | [ {"i":0,"dog":"Evie","greeting":"Ahoy, Evie!"},{"i":1,"dog":"Casper","greeting":"Ahoy, Casper!"},{"i":2,"dog":"Indy","greeting":"Ahoy, Indy!"},{"i":3,"dog":"Kira","greeting":"Ahoy, Kira!"}] |
155
165
166
+ ** dogNames** shows the dog names from the array of objects; ** sayHi** concatenates "Hello" and each of the dog names; and ** mapObject** creates another array of objects.
167
+
156
168
## reduce
157
169
158
170
` reduce(inputArray, initialValue, lambda expression) `
175
187
176
188
### Example
177
189
178
- The following example shows how to use the reduce function.
190
+ The following examples show how to use the reduce function.
179
191
180
192
``` bicep
181
193
var dogs = [
@@ -203,7 +215,18 @@ var dogs = [
203
215
var ages = map(dogs, dog => dog.age)
204
216
output totalAge int = reduce(ages, 0, (cur, prev) => cur + prev)
205
217
output totalAgeAdd1 int = reduce(ages, 1, (cur, prev) => cur + prev)
218
+ ```
219
+
220
+ The output from the preceding example is:
206
221
222
+ | Name | Type | Value |
223
+ | ---- | ---- | ----- |
224
+ | totalAge | int | 18 |
225
+ | totalAgeAdd1 | int | 19 |
226
+
227
+ ** totalAge** sums the ages of the dogs; ** totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.
228
+
229
+ ``` bicep
207
230
output reduceObjectUnion object = reduce([
208
231
{ foo: 123 }
209
232
{ bar: 456 }
@@ -215,11 +238,9 @@ The output from the preceding example is:
215
238
216
239
| Name | Type | Value |
217
240
| ---- | ---- | ----- |
218
- | totalAge | int | 18 |
219
- | totalAgeAdd1 | int | 19 |
220
241
| reduceObjectUnion | object | {"foo":123,"bar":456,"baz":789} |
221
242
222
- In the last output, the [ union] ( ./bicep-functions-object.md#union ) function returns a single object with all elements from the parameters. The function call unionizes the key value pairs of the objects.
243
+ The [ union] ( ./bicep-functions-object.md#union ) function returns a single object with all elements from the parameters. The function call unionizes the key value pairs of the objects into a new object .
223
244
224
245
## sort
225
246
@@ -268,10 +289,10 @@ var dogs = [
268
289
}
269
290
]
270
291
271
- output dogsByAge array = sort(dogs, (a, b) => a.age <= b.age)
292
+ output dogsByAge array = sort(dogs, (a, b) => a.age < b.age)
272
293
```
273
294
274
- The output from the preceding example is :
295
+ The output from the preceding example sorts the dog objects from the youngest to the oldest :
275
296
276
297
| Name | Type | Value |
277
298
| ---- | ---- | ----- |
0 commit comments