Skip to content

Commit 56b12d1

Browse files
committed
ARM/Bicep groupBy function
1 parent 06147b3 commit 56b12d1

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,43 @@ The output from the preceding example:
9797

9898
**filterdLoop** shows the numbers in an array that are greater than 5; and **isEven** shows the even numbers in the array.
9999

100+
## groupBy
101+
102+
`groupBy(inputArray, lambda expression)`
103+
104+
Creates an object with array values from an array, using a grouping condition:
105+
106+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
107+
108+
### Parameters
109+
110+
| Parameter | Required | Type | Description |
111+
|:--- |:--- |:--- |:--- |
112+
| inputArray |Yes |array |The array for grouping.|
113+
| lambda expression |Yes |expression |The lambda expression is applied to each input array element, and group the elements using the grouping condition.|
114+
115+
### Return value
116+
117+
An object.
118+
119+
### Examples
120+
121+
The following examples show how to use the `groupBy` function.
122+
123+
```bicep
124+
var groupObject = groupBy(['foo', 'bar', 'baz'], x => substring(x, 0, 1))
125+
126+
output outObject object = groupObject
127+
```
128+
129+
The output from the preceding example shows the dogs that are five or older:
130+
131+
| Name | Type | Value |
132+
| ---- | ---- | ----- |
133+
| outObject | Object | {"f":["foo"],"b":["bar","baz"]} |
134+
135+
**outObject** shows an object that groups the array elements by their first letters.
136+
100137
## map
101138

102139
`map(inputArray, lambda expression)`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The following functions are available for loading the content from external file
9191
The following functions are available for working with lambda expressions. All of these functions are in the `sys` namespace.
9292

9393
* [filter](bicep-functions-lambda.md#filter)
94+
* [groupBy](bicep-functions-lambda.md#groupby)
9495
* [map](bicep-functions-lambda.md#map)
9596
* [reduce](bicep-functions-lambda.md#reduce)
9697
* [sort](bicep-functions-lambda.md#sort)

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ This article describes the lambda functions to use in ARM templates. [Lambda fun
1414
lambda(<lambda variable>, [<lambda variable>, ...], <expression>)
1515
```
1616

17-
1817
> [!TIP]
1918
> We recommend [Bicep](../bicep/overview.md) because it offers the same capabilities as ARM templates and the syntax is easier to use. To learn more, see [deployment](../bicep/bicep-functions-deployment.md) functions.
2019
@@ -139,6 +138,54 @@ The output from the preceding example:
139138

140139
**filterdLoop** shows the numbers in an array that are greater than 5; and **isEven** shows the even numbers in the array.
141140

141+
## groupBy
142+
143+
`groupBy(inputArray, lambda expression)`
144+
145+
Creates an object with array values from an array, using a grouping condition:
146+
147+
In Bicep, use the [groupBy](../bicep/bicep-functions-lambda.md#groupby) function.
148+
149+
### Parameters
150+
151+
| Parameter | Required | Type | Description |
152+
|:--- |:--- |:--- |:--- |
153+
| inputArray |Yes |array |The array for grouping.|
154+
| lambda expression |Yes |expression |The lambda expression is applied to each input array element, and group the elements using the grouping condition.|
155+
156+
### Return value
157+
158+
An object.
159+
160+
### Examples
161+
162+
The following example show how to use the `groupBy` function.
163+
164+
```json
165+
{
166+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
167+
"contentVersion": "1.0.0.0",
168+
"variables": {
169+
"groupObject": "[groupBy(createArray('foo', 'bar', 'baz'), lambda('x', substring(lambdaVariables('x'), 0, 1)))]"
170+
},
171+
"resources": [],
172+
"outputs": {
173+
"outObject": {
174+
"type": "object",
175+
"value": "[variables('groupObject')]"
176+
}
177+
}
178+
}
179+
```
180+
181+
The output from the preceding example shows the dogs that are five or older:
182+
183+
| Name | Type | Value |
184+
| ---- | ---- | ----- |
185+
| outObject | Object | {"f":["foo"],"b":["bar","baz"]} |
186+
187+
**outObject** shows an object that groups the array elements by their first letters.
188+
142189
## map
143190

144191
`map(inputArray, lambda function)`

0 commit comments

Comments
 (0)