Skip to content

Commit cb1a3d4

Browse files
committed
add a filter sample
1 parent 2e6d2cc commit cb1a3d4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ var dogs = [
6666
interests: ['Butter']
6767
}
6868
{
69-
name: 'Kira'
69+
name: 'Cira'
7070
age: 8
7171
interests: ['Rubs']
7272
}
7373
]
7474
7575
output oldDogs array = filter(dogs, dog => dog.age >=5)
76+
output dogNameIndex array = filter(dogs, (val, i) => i < 2 && substring(val.name, 0, 1) == 'C')
7677
```
7778

78-
The output from the preceding example shows the dogs that are five or older:
79+
The outputs from the preceding example:
7980

8081
| Name | Type | Value |
8182
| ---- | ---- | ----- |
8283
| oldDogs | Array | [{"name":"Evie","age":5,"interests":["Ball","Frisbee"]},{"name":"Kira","age":8,"interests":["Rubs"]}] |
84+
| dogNameIndex | Array | [{"name":"Casper","age":3,"interests":["Other dogs"]}] |
85+
86+
**oldDogs** lists the dogs that are five or older; **dogNameIndex** identifies the dog(s) whose index number is less than two and whose name starts with the letter "C".
8387

8488
```bicep
8589
var itemForLoop = [for item in range(0, 10): item]
@@ -88,7 +92,7 @@ output filteredLoop array = filter(itemForLoop, i => i > 5)
8892
output isEven array = filter(range(0, 10), i => 0 == i % 2)
8993
```
9094

91-
The output from the preceding example:
95+
The outputs from the preceding example:
9296

9397
| Name | Type | Value |
9498
| ---- | ---- | ----- |
@@ -118,15 +122,15 @@ An object.
118122

119123
### Examples
120124

121-
The following examples show how to use the `groupBy` function.
125+
The following example show how to use the `groupBy` function.
122126

123127
```bicep
124128
var inputArray = ['foo', 'bar', 'baz']
125129
126130
output outObject object = groupBy(inputArray, x => substring(x, 0, 1))
127131
```
128132

129-
The output from the preceding example shows the dogs that are five or older:
133+
The output from the preceding example:
130134

131135
| Name | Type | Value |
132136
| ---- | ---- | ----- |
@@ -191,7 +195,7 @@ output mapArray array = map(range(0, length(dogs)), i => {
191195
output mapArrayIndex array = map(dogs, (x, i) => { index: i, val: x.name})
192196
```
193197

194-
The output from the preceding example is:
198+
The outputs from the preceding example are:
195199

196200
| Name | Type | Value |
197201
| ---- | ---- | ----- |
@@ -292,7 +296,7 @@ output totalAgeAdd1 int = reduce(ages, 1, (cur, next) => cur + next)
292296
output oddAge int = reduce(ages, 0, (cur, next, i) => (i % 2 == 0) ? cur + next : cur)
293297
```
294298

295-
The output from the preceding example is:
299+
The outputs from the preceding example are:
296300

297301
| Name | Type | Value |
298302
| ---- | ---- | ----- |

articles/azure-resource-manager/templates/template-functions-lambda.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,23 @@ The following examples show how to use the `filter` function.
9191
"oldDogs": {
9292
"type": "array",
9393
"value": "[filter(variables('dogs'), lambda('dog', greaterOrEquals(lambdaVariables('dog').age, 5)))]"
94+
},
95+
"dogNameIndex": {
96+
"type": "array",
97+
"value": "[filter(variables('dogs'), lambda('val', 'i', and(less(lambdaVariables('i'), 2), equals(substring(lambdaVariables('val').name, 0, 1), 'C'))))]"
9498
}
9599
}
96100
}
97101
```
98102

99-
The output from the preceding example shows the dogs that are five or older:
103+
The outputs from the preceding example:
100104

101105
| Name | Type | Value |
102106
| ---- | ---- | ----- |
103107
| oldDogs | Array | [{"name":"Evie","age":5,"interests":["Ball","Frisbee"]},{"name":"Kira","age":8,"interests":["Rubs"]}] |
108+
| dogNameIndex | Array | [{"name":"Casper","age":3,"interests":["Other dogs"]}] |
109+
110+
**oldDogs** lists the dogs that are five or older; **dogNameIndex** identifies the dog(s) whose index number is less than two and whose name starts with the letter "C".
104111

105112
```json
106113
{

0 commit comments

Comments
 (0)