Skip to content

Commit 4f7ac33

Browse files
authored
Merge pull request #274990 from mumian/0510-function-groupby
ARM/Bicep groupBy function
2 parents afebf83 + e64c754 commit 4f7ac33

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep functions - lambda
33
description: Describes the lambda functions to use in a Bicep file.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 05/13/2024
6+
ms.date: 05/21/2024
77
---
88
# Lambda functions for Bicep
99

@@ -38,7 +38,7 @@ Namespace: [sys](bicep-functions.md#namespaces-for-functions).
3838
| Parameter | Required | Type | Description |
3939
|:--- |:--- |:--- |:--- |
4040
| inputArray |Yes |array |The array to filter.|
41-
| lambda expression |Yes |expression |The lambda expression is applied to each input array element. If the result is true, the item will be included in the output array; otherwise, the item is discarded.|
41+
| lambda expression |Yes |expression |The lambda expression is applied to each input array element. If the result is true, the item is included in the output array; otherwise, the item is discarded.|
4242

4343
### Return value
4444

@@ -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 inputArray = ['foo', 'bar', 'baz']
125+
126+
output outObject object = groupBy(inputArray, x => substring(x, 0, 1))
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
* [mapValue](bicep-functions-lambda.md#mapvalues)
9697
* [reduce](bicep-functions-lambda.md#reduce)

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

Lines changed: 52 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,58 @@ 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 shows 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+
"inputArray": [
170+
"foo",
171+
"bar",
172+
"baz"
173+
]
174+
},
175+
"resources": [],
176+
"outputs": {
177+
"outObject": {
178+
"type": "object",
179+
"value": "[groupBy(variables('inputArray'), lambda('x', substring(lambdaVariables('x'), 0, 1)))]"
180+
}
181+
}
182+
}
183+
```
184+
185+
The output from the preceding example shows the dogs that are five or older:
186+
187+
| Name | Type | Value |
188+
| ---- | ---- | ----- |
189+
| outObject | Object | {"f":["foo"],"b":["bar","baz"]} |
190+
191+
**outObject** shows an object that groups the array elements by their first letters.
192+
142193
## map
143194

144195
`map(inputArray, lambda function)`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ For Bicep files, use the [deployment](../bicep/bicep-functions-deployment.md) fu
141141
Resource Manager provides the following functions for working with lambda expressions.
142142

143143
* [filter](template-functions-lambda.md#filter)
144+
* [groupBy](template-functions-lambda.md#groupby)
144145
* [map](template-functions-lambda.md#map)
145146
* [mapValues](template-functions-lambda.md#mapvalues)
146147
* [reduce](template-functions-lambda.md#reduce)

0 commit comments

Comments
 (0)