You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/bicep-functions-lambda.md
+21-13Lines changed: 21 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ This article describes the lambda functions to use in Bicep. [Lambda expressions
20
20
21
21
Bicep lambda function has these limitations:
22
22
23
-
- Lambda expression can only be specified directly as function arguments in these functions: [`filter()`](#filter), [`map()`](#map), [`reduce()`](#reduce), [`sort()`](#sort), and [`toObject()`](#toobject).
23
+
- Lambda expression can only be specified directly as function arguments in these functions: [`filter()`](#filter), [`groupBy()`](#groupby), [`map()`](#map), [`mapValues()`](#mapvalues), [`reduce()`](#reduce), [`sort()`](#sort), and [`toObject()`](#toobject).
24
24
- Using lambda variables (the temporary variables used in the lambda expressions) inside resource or module array access isn't currently supported.
25
25
- Using lambda variables inside the [`listKeys`](./bicep-functions-resource.md#list) function isn't currently supported.
26
26
- Using lambda variables inside the [reference](./bicep-functions-resource.md#reference) function isn't currently supported.
@@ -66,20 +66,24 @@ var dogs = [
66
66
interests: ['Butter']
67
67
}
68
68
{
69
-
name: 'Kira'
69
+
name: 'Cira'
70
70
age: 8
71
71
interests: ['Rubs']
72
72
}
73
73
]
74
74
75
75
output oldDogs array = filter(dogs, dog => dog.age >=5)
**oldDogs** lists the dogs that are five or older; **dogNameIndex** identifies the dogs whose index number is less than two and whose name starts with the letter "C".
83
87
84
88
```bicep
85
89
var itemForLoop = [for item in range(0, 10): item]
@@ -88,7 +92,7 @@ output filteredLoop array = filter(itemForLoop, i => i > 5)
88
92
output isEven array = filter(range(0, 10), i => 0 == i % 2)
89
93
```
90
94
91
-
The output from the preceding example:
95
+
The outputs from the preceding example:
92
96
93
97
| Name | Type | Value |
94
98
| ---- | ---- | ----- |
@@ -118,15 +122,15 @@ An object.
118
122
119
123
### Examples
120
124
121
-
The following examples show how to use the `groupBy` function.
125
+
The following example shows how to use the `groupBy` function.
122
126
123
127
```bicep
124
128
var inputArray = ['foo', 'bar', 'baz']
125
129
126
130
output outObject object = groupBy(inputArray, x => substring(x, 0, 1))
127
131
```
128
132
129
-
The output from the preceding example shows the dogs that are five or older:
133
+
The output from the preceding example:
130
134
131
135
| Name | Type | Value |
132
136
| ---- | ---- | ----- |
@@ -183,22 +187,24 @@ var dogs = [
183
187
184
188
output dogNames array = map(dogs, dog => dog.name)
185
189
output sayHi array = map(dogs, dog => 'Hello ${dog.name}!')
186
-
output mapObject array = map(range(0, length(dogs)), i => {
190
+
output mapArray array = map(range(0, length(dogs)), i => {
**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.
207
+
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; **mapArray**and **mapArrayIndex**create another two arrays of objects.
202
208
203
209
## mapValues
204
210
@@ -287,16 +293,18 @@ var dogs = [
287
293
var ages = map(dogs, dog => dog.age)
288
294
output totalAge int = reduce(ages, 0, (cur, next) => cur + next)
289
295
output totalAgeAdd1 int = reduce(ages, 1, (cur, next) => cur + next)
296
+
output oddAge int = reduce(ages, 0, (cur, next, i) => (i % 2 == 0) ? cur + next : cur)
290
297
```
291
298
292
-
The output from the preceding example is:
299
+
The outputs from the preceding example are:
293
300
294
301
| Name | Type | Value |
295
302
| ---- | ---- | ----- |
296
303
| totalAge | int | 18 |
297
304
| totalAgeAdd1 | int | 19 |
305
+
| oddAge | int | 7 |
298
306
299
-
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.
307
+
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.**oddAge** sums the ages of dogs that are located at even indices, specifically **5** (Evie) and **2** (Indy).
300
308
301
309
```bicep
302
310
output reduceObjectUnion object = reduce([
@@ -477,4 +485,4 @@ The preceding example generates an object based on an array.
477
485
478
486
## Next steps
479
487
480
-
- See [Bicep functions - arrays](./bicep-functions-array.md) for additional arrayrelated Bicep functions.
488
+
- See [Bicep functions - arrays](./bicep-functions-array.md) for more array-related Bicep functions.
ARM template lambda function has these limitations:
23
23
24
-
- Lambda function can only be specified directly as function arguments in these functions: [`filter()`](#filter), [`map()`](#map), [`reduce()`](#reduce), [`sort()`](#sort), and [`toObject()`](#toobject).
24
+
- Lambda expression can only be specified directly as function arguments in these functions: [`filter()`](#filter), [`groupBy()`](#groupby), [`map()`](#map), [`mapValues()`](#mapvalues), [`reduce()`](#reduce), [`sort()`](#sort), and [`toObject()`](#toobject).
25
25
- Using lambda variables (the temporary variables used in the lambda functions) inside resource or module array access isn't currently supported.
26
26
- Using lambda variables inside the [`listKeys`](./template-functions-resource.md#list) function isn't currently supported.
27
27
- Using lambda variables inside the [reference](./template-functions-resource.md#reference) function isn't currently supported.
@@ -91,16 +91,23 @@ The following examples show how to use the `filter` function.
**oldDogs** lists the dogs that are five or older; **dogNameIndex** identifies the dogs whose index number is less than two and whose name starts with the letter "C".
104
111
105
112
```json
106
113
{
@@ -260,9 +267,13 @@ The following example shows how to use the `map` function.
**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.
291
+
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; **mapArray**and **mapArrayIndex**create another two arrays of objects.
280
292
281
293
## mapValues
282
294
@@ -400,6 +412,10 @@ The following examples show how to use the `reduce` function.
@@ -411,8 +427,9 @@ The output from the preceding example is:
411
427
| ---- | ---- | ----- |
412
428
| totalAge | int | 18 |
413
429
| totalAgeAdd1 | int | 19 |
430
+
| oddAge | int | 7 |
414
431
415
-
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.
432
+
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.**oddAge** sums the ages of dogs that are located at even indices, specifically **5** (Evie) and **2** (Indy).
0 commit comments