Skip to content

Commit 0188869

Browse files
committed
incorporate Alex's comments
1 parent 3f02a3e commit 0188869

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

articles/azure-resource-manager/bicep/bicep-functions-lambda.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Describes the lambda functions to use in a Bicep file.
44
author: mumian
55
ms.topic: conceptual
66
ms.author: jgao
7-
ms.date: 09/15/2022
7+
ms.date: 09/20/2022
88

99
---
1010
# Lambda functions for Bicep
@@ -46,9 +46,9 @@ Namespace: [sys](bicep-functions.md#namespaces-for-functions).
4646

4747
An array.
4848

49-
### Example
49+
### Examples
5050

51-
The following example shows how to use the filter function.
51+
The following examples show how to use the filter function.
5252

5353
```bicep
5454
var dogs = [
@@ -73,21 +73,31 @@ var dogs = [
7373
interests: ['Rubs']
7474
}
7575
]
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
7687
var itemForLoop = [for item in range(0, 10): item]
7788
7889
output filteredLoop array = filter(itemForLoop, i => i > 5)
7990
output isEven array = filter(range(0, 10), i => 0 == i % 2)
80-
81-
output oldDogs array = filter(dogs, dog => dog.age >=5)
8291
```
8392

84-
The output from the preceding example shows the dogs that are five or older:
93+
The output from the preceding example:
8594

8695
| Name | Type | Value |
8796
| ---- | ---- | ----- |
8897
| filteredLoop | Array | [6, 7, 8, 9] |
8998
| 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.
91101

92102
## map
93103

@@ -153,6 +163,8 @@ The output from the preceding example is:
153163
| sayHi | Array | ["Hello Evie!","Hello Casper!","Hello Indy!","Hello Kira!"] |
154164
| 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!"}] |
155165

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+
156168
## reduce
157169

158170
`reduce(inputArray, initialValue, lambda expression)`
@@ -175,7 +187,7 @@ Any.
175187

176188
### Example
177189

178-
The following example shows how to use the reduce function.
190+
The following examples show how to use the reduce function.
179191

180192
```bicep
181193
var dogs = [
@@ -203,7 +215,18 @@ var dogs = [
203215
var ages = map(dogs, dog => dog.age)
204216
output totalAge int = reduce(ages, 0, (cur, prev) => cur + prev)
205217
output totalAgeAdd1 int = reduce(ages, 1, (cur, prev) => cur + prev)
218+
```
219+
220+
The output from the preceding example is:
206221

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
207230
output reduceObjectUnion object = reduce([
208231
{ foo: 123 }
209232
{ bar: 456 }
@@ -215,11 +238,9 @@ The output from the preceding example is:
215238

216239
| Name | Type | Value |
217240
| ---- | ---- | ----- |
218-
| totalAge | int | 18 |
219-
| totalAgeAdd1 | int | 19 |
220241
| reduceObjectUnion | object | {"foo":123,"bar":456,"baz":789} |
221242

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.
223244

224245
## sort
225246

@@ -268,10 +289,10 @@ var dogs = [
268289
}
269290
]
270291
271-
output dogsByAge array = sort(dogs, (a, b) => a.age <= b.age)
292+
output dogsByAge array = sort(dogs, (a, b) => a.age < b.age)
272293
```
273294

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:
275296

276297
| Name | Type | Value |
277298
| ---- | ---- | ----- |

0 commit comments

Comments
 (0)