Skip to content

Commit a909230

Browse files
Merge pull request #1043 from Gijsreyn/add-reference-array-functions
Add reference documentation for array functions
2 parents d4cee44 + b11f060 commit a909230

File tree

3 files changed

+558
-0
lines changed

3 files changed

+558
-0
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
description: Reference for the 'array' DSC configuration document function
3+
ms.date: 08/12/2025
4+
ms.topic: reference
5+
title: array
6+
---
7+
8+
# array
9+
10+
## Synopsis
11+
12+
Creates an array from the given elements (strings, numbers, arrays, or objects).
13+
14+
## Syntax
15+
16+
```Syntax
17+
array(<element1>, <element2>, ...)
18+
```
19+
20+
## Description
21+
22+
The `array()` function creates an array from the provided arguments, allowing
23+
mixed data types within the same array. Unlike `createArray()` which requires
24+
all elements to be the same type, `array()` accepts any combination of strings,
25+
numbers, arrays, and objects as arguments.
26+
27+
This function is useful when you need to combine different types of data into a
28+
single collection, such as mixing configuration values, computed results, and
29+
structured metadata in deployment scenarios.
30+
31+
## Examples
32+
33+
### Example 1 - Build a deployment plan
34+
35+
This example demonstrates combining different data types to create a comprehensive
36+
deployment configuration. The array contains an existing server list, a numeric
37+
batch size, and a configuration object with deployment strategy details.
38+
39+
```yaml
40+
# array.example.1.dsc.config.yaml
41+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
42+
parameters:
43+
webServers:
44+
type: array
45+
defaultValue:
46+
- web01
47+
- web02
48+
batchSize:
49+
type: int
50+
defaultValue: 2
51+
resources:
52+
- name: Deployment Plan
53+
type: Microsoft.DSC.Debug/Echo
54+
properties:
55+
output: "[array(parameters('webServers'), parameters('batchSize'), createObject('strategy', 'blue-green'))]"
56+
```
57+
58+
```bash
59+
dsc config get --file array.example.1.dsc.config.yaml
60+
```
61+
62+
```yaml
63+
results:
64+
- name: Deployment Plan
65+
type: Microsoft.DSC.Debug/Echo
66+
result:
67+
actualState:
68+
output:
69+
- - web01
70+
- web02
71+
- 2
72+
- strategy: blue-green
73+
messages: []
74+
hadErrors: false
75+
```
76+
77+
### Example 2 - Compose mixed telemetry payload parts
78+
79+
This example shows how to construct a telemetry payload by combining a string
80+
identifier, structured metadata object, and numeric status code into a single
81+
array for logging or monitoring systems.
82+
83+
```yaml
84+
# array.example.2.dsc.config.yaml
85+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
86+
parameters:
87+
correlationId:
88+
type: string
89+
defaultValue: ABC123
90+
resources:
91+
- name: Telemetry Payload
92+
type: Microsoft.DSC.Debug/Echo
93+
properties:
94+
output:
95+
payload: "[array(parameters('correlationId'), createObject('severity', 'info'), 200)]"
96+
```
97+
98+
```bash
99+
dsc config get --file array.example.2.dsc.config.yaml
100+
```
101+
102+
```yaml
103+
results:
104+
- name: Telemetry Payload
105+
type: Microsoft.DSC.Debug/Echo
106+
result:
107+
actualState:
108+
output:
109+
payload:
110+
- ABC123
111+
- severity: info
112+
- 200
113+
messages: []
114+
hadErrors: false
115+
```
116+
117+
### Example 3 - Combine generated and literal collections
118+
119+
This example demonstrates nesting arrays and objects within a parent array,
120+
showing how `array()` can combine results from other DSC functions like
121+
`createArray()` and `createObject()` with literal values.
122+
123+
```yaml
124+
# array.example.3.dsc.config.yaml
125+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
126+
resources:
127+
- name: Combined Collections
128+
type: Microsoft.DSC.Debug/Echo
129+
properties:
130+
output:
131+
combined: "[array(createArray('a','b'), array(1,2), createObject('k','v'))]"
132+
```
133+
134+
```bash
135+
dsc config get --file array.example.3.dsc.config.yaml
136+
```
137+
138+
```yaml
139+
results:
140+
- name: Combined Collections
141+
type: Microsoft.DSC.Debug/Echo
142+
result:
143+
actualState:
144+
output:
145+
combined:
146+
- - a
147+
- b
148+
- - 1
149+
- 2
150+
- k: v
151+
messages: []
152+
hadErrors: false
153+
```
154+
155+
## Parameters
156+
157+
### element1, element2, ...
158+
159+
The elements to include in the array.
160+
161+
```yaml
162+
Type: string, number, array, or object
163+
Required: false
164+
Multiplicity: 0 or more
165+
```
166+
167+
Each element provided as an argument will be added to the resulting array in the
168+
order specified. All elements must be one of the four accepted types: string,
169+
number (integer), array, or object. Boolean and null values are not supported.
170+
171+
## Output
172+
173+
Returns a new array containing the provided elements in order.
174+
175+
```yaml
176+
Type: array
177+
```
178+
179+
## Related functions
180+
181+
- [`createArray()`][00] - Creates a homogeneous array (all elements same type)
182+
- [`createObject()`][01] - Builds an object from key/value pairs
183+
- [`first()`][02] - Gets the first element from an array
184+
- [`indexOf()`][03] - Finds the index of an item in an array
185+
186+
<!-- Link reference definitions -->
187+
[00]: ./createArray.md
188+
[01]: ./createObject.md
189+
[02]: ./first.md
190+
[03]: ./indexOf.md
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
description: Reference for the 'first' DSC configuration document function
3+
ms.date: 08/12/2025
4+
ms.topic: reference
5+
title: first
6+
---
7+
8+
# first
9+
10+
## Synopsis
11+
12+
Returns the first element of an array or the first character of a string.
13+
14+
## Syntax
15+
16+
```Syntax
17+
first(<arrayOrString>)
18+
```
19+
20+
## Description
21+
22+
The `first()` function extracts the first element from an array or the first
23+
character from a string. When used with arrays, it returns the actual first
24+
element preserving its original data type (string, number, array, or object).
25+
When used with strings, it returns a new single-character string containing
26+
the first Unicode character.
27+
28+
This function is particularly useful for accessing the primary or default item
29+
from a collection, or extracting prefixes from identifiers and codes. The
30+
function will return an error if the input array or string is empty.
31+
32+
## Examples
33+
34+
### Example 1 - Get the first server hostname
35+
36+
This example shows how to extract the primary server from a list of servers,
37+
which could be useful for identifying the lead server in a cluster or getting
38+
the default target for deployment operations.
39+
40+
```yaml
41+
# first.example.1.dsc.config.yaml
42+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
43+
parameters:
44+
servers:
45+
type: array
46+
defaultValue:
47+
- web01
48+
- web02
49+
resources:
50+
- name: First Server
51+
type: Microsoft.DSC.Debug/Echo
52+
properties:
53+
output:
54+
firstServer: "[first(parameters('servers'))]"
55+
```
56+
57+
```bash
58+
dsc config get --file first.example.1.dsc.config.yaml
59+
```
60+
61+
```yaml
62+
results:
63+
- name: First Server
64+
type: Microsoft.DSC.Debug/Echo
65+
result:
66+
actualState:
67+
output:
68+
firstServer: web01
69+
messages: []
70+
hadErrors: false
71+
```
72+
73+
### Example 2 - Extract leading character for a prefix
74+
75+
This example demonstrates extracting the first character from an environment
76+
code to create abbreviated prefixes for resource naming or tagging schemes.
77+
78+
```yaml
79+
# first.example.2.dsc.config.yaml
80+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
81+
parameters:
82+
environmentCode:
83+
type: string
84+
defaultValue: Prod
85+
resources:
86+
- name: Prefix Builder
87+
type: Microsoft.DSC.Debug/Echo
88+
properties:
89+
output:
90+
prefix: "[first(parameters('environmentCode'))]"
91+
```
92+
93+
```bash
94+
dsc config get --file first.example.2.dsc.config.yaml
95+
```
96+
97+
```yaml
98+
results:
99+
- name: Prefix Builder
100+
type: Microsoft.DSC.Debug/Echo
101+
result:
102+
actualState:
103+
output:
104+
prefix: P
105+
messages: []
106+
hadErrors: false
107+
```
108+
109+
### Example 3 - Chain with array construction
110+
111+
This example shows how `first()` can be combined with `array()` to get the
112+
first element from a dynamically constructed array containing mixed data types.
113+
114+
```yaml
115+
# first.example.3.dsc.config.yaml
116+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
117+
resources:
118+
- name: Chained Example
119+
type: Microsoft.DSC.Debug/Echo
120+
properties:
121+
output:
122+
firstMixed: "[first(array(createArray('a','b'), createObject('k','v')))]"
123+
```
124+
125+
```bash
126+
dsc config get --file first.example.3.dsc.config.yaml
127+
```
128+
129+
```yaml
130+
results:
131+
- name: Chained Example
132+
type: Microsoft.DSC.Debug/Echo
133+
result:
134+
actualState:
135+
output:
136+
firstMixed:
137+
- a
138+
- b
139+
messages: []
140+
hadErrors: false
141+
```
142+
143+
## Parameters
144+
145+
### input
146+
147+
The array or string to extract the first element or character from.
148+
149+
```yaml
150+
Type: array or string
151+
Required: true
152+
```
153+
154+
If the input is an array, the first element is returned with its original data
155+
type preserved. If the input is a string, the first Unicode character is
156+
returned as a new string. Empty arrays and empty strings will result in an
157+
error.
158+
159+
## Output
160+
161+
Returns the first element or character.
162+
163+
```yaml
164+
Type: string | number | array | object
165+
```
166+
167+
## Related functions
168+
169+
- [`array()`][00] - Creates an array from heterogeneous elements
170+
- [`createArray()`][01] - Creates a homogeneous array
171+
- [`indexOf()`][02] - Finds the index of an item in an array
172+
173+
<!-- Link reference definitions -->
174+
[00]: ./array.md
175+
[01]: ./createArray.md
176+
[02]: ./indexOf.md

0 commit comments

Comments
 (0)