Skip to content

Commit a30946e

Browse files
committed
revise: more updates to stdlib
* Adds some designations of WDL v1.2 functions. * Adds String Array functions.
1 parent 32df4d2 commit a30946e

File tree

4 files changed

+158
-7
lines changed

4 files changed

+158
-7
lines changed

.vitepress/config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ export default defineConfig({
147147
text: "File functions",
148148
link: "/reference/stdlib/file",
149149
},
150+
{
151+
text: "String Array functions",
152+
link: "/reference/stdlib/string-array",
153+
},
150154
],
151155
collapsed: true,
152156
},

reference/stdlib/file.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File Functions
22

33
- [`basename`](#basename)
4-
- [`join_paths`](#join-paths)
4+
- [`join_paths`](#join-paths) <Badge type="tip" text="v1.2" />
55
- [`glob`](#glob)
66
- [`size`](#size)
77
- [`stdout`](#stdout)
@@ -31,7 +31,6 @@ separator in the path.
3131
The optional second parameter specifies a literal suffix to remove from the file name.
3232
If the file name does not end with the specified suffix then it is ignored.
3333

34-
3534
**Signatures**
3635

3736
```wdl
@@ -60,7 +59,7 @@ String bn = basename("/path/to/file.txt", ".txt")
6059
# `bn` contains `"file"`.
6160
```
6261

63-
## `join_paths`
62+
## `join_paths` <Badge type="tip" text="Requires WDL v1.2" />
6463

6564
Joins together two or more paths into an absolute path in the host filesystem.
6665

reference/stdlib/string-array.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# String Array Functions
2+
3+
- [`prefix`](#prefix)
4+
- [`suffix`](#suffix)
5+
- [`quote`](#quote)
6+
- [`squote`](#squote)
7+
- [`sep`](#sep)
8+
9+
## `prefix`
10+
11+
Adds a prefix to each element of the input array of primitive values. Equivalent to
12+
evaluating `"~{prefix}~{array[i]}"` for each `i` in `range(length(array))`.
13+
14+
**Signatures**
15+
16+
```wdl
17+
Array[String] prefix(String, Array[P])
18+
```
19+
20+
**Parameters**
21+
22+
1. **`String`**: The prefix to prepend to each element in the array.
23+
2. **`Array[P]`**: Array with a primitive element type.
24+
25+
**Returns**
26+
27+
1. An `Array[String]` with the prefixed elements of the input array.
28+
29+
**Example**
30+
31+
```wdl
32+
Array[String] names = ["John", "Jane", "world"]
33+
String greetings = prefix("Hello, ", names)
34+
# `greetings` now contains `["Hello, John", "Hello, Jane", "Hello, world"]`.
35+
```
36+
37+
## `suffix`
38+
39+
Adds a suffix to each element of the input array of primitive values. Equivalent to
40+
evaluating `"~{array[i]}~{suffix}"` for each `i` in `range(length(array))`.
41+
42+
**Signatures**
43+
44+
```wdl
45+
Array[String] suffix(String, Array[P])
46+
```
47+
48+
**Parameters**
49+
50+
1. **`String`**: The suffix to append to each element in the array.
51+
2. **`Array[P]`**: Array with a primitive element type.
52+
53+
**Returns**
54+
55+
1. An `Array[String]` the suffixed elements of the input array.
56+
57+
**Example**
58+
59+
```wdl
60+
Array[String] names = ["John", "Jane"]
61+
String responses = suffix(" says 'hi!'", names)
62+
# `responses` now contains `["John says 'hi!'", "Jane says 'hi!'"]`.
63+
```
64+
65+
## `quote`
66+
67+
Adds double-quotes (`"`) around each element of the input array of primitive values.
68+
Equivalent to evaluating `'"~{array[i]}"'` for each `i` in `range(length(array))`.
69+
70+
**Signatures**
71+
72+
```wdl
73+
Array[String] quote(Array[P])
74+
```
75+
76+
**Parameters**
77+
78+
1. **`Array[P]`**: Array with a primitive element type.
79+
80+
**Returns**
81+
82+
1. An `Array[String]` the double-quoted elements of the input array.
83+
84+
**Example**
85+
86+
```wdl
87+
Array[String] numbers = [1, 2, 3]
88+
String quoted = quote(numbers)
89+
# `quoted` now contains `["\"1\"", "\"2\"", "\"3\""]`.
90+
```
91+
92+
## `squote`
93+
94+
Adds single-quotes (`'`) around each element of the input array of primitive values.
95+
Equivalent to evaluating `"'~{array[i]}'"` for each `i` in `range(length(array))`.
96+
97+
**Signatures**
98+
99+
```wdl
100+
Array[String] squote(Array[P])
101+
```
102+
103+
**Parameters**
104+
105+
1. **`Array[P]`**: Array with a primitive element type.
106+
107+
**Returns**
108+
109+
1. An `Array[String]` the single-quoted elements of the input array.
110+
111+
**Example**
112+
113+
```wdl
114+
Array[String] numbers = [1, 2, 3]
115+
String quoted = squote(numbers)
116+
# `quoted` now contains `["'1'", "'2'", "'3'"]`.
117+
```
118+
119+
## `sep`
120+
121+
Concatenates the elements of an array together into a string with the given separator
122+
between consecutive elements. There are always `N-1` separators in the output string,
123+
where `N` is the length of the input array. A separator is never added after the last
124+
element. Returns an empty string if the array is empty.
125+
126+
**Signatures**
127+
128+
```wdl
129+
String sep(String, Array[P])
130+
```
131+
132+
**Parameters**
133+
134+
1. `String`: Separator string.
135+
2. `Array[P]`: Array of strings to concatenate.
136+
137+
**Returns**
138+
139+
1. A `String` with the concatenated elements of the array delimited by the separator
140+
string.
141+
142+
**Example**
143+
144+
```wdl
145+
Array[String] letters = ["a", "b", "c", "d"]
146+
String letters_with_commas = sep(", ", letters)
147+
# `letters_with_commas` now contains `"a, b, c, d"`.
148+
```

reference/stdlib/string.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# String Functions
22

3-
- [`find`](#find)
4-
- [`matches`](#matches)
3+
- [`find`](#find) <Badge type="tip" text="v1.2" />
4+
- [`matches`](#matches) <Badge type="tip" text="v1.2" />
55
- [`sub`](#sub)
66

7-
## `find`
7+
## `find` <Badge type="tip" text="Requires WDL v1.2" />
88

99
Given two `String` parameters `input` and `pattern`, searches for the occurrence of
1010
`pattern` within `input` and returns the first match or `None` if there are no matches.
@@ -42,7 +42,7 @@ String? match = find("Hello, world!", "e..o");
4242
# `match` now contains `ello`.
4343
```
4444

45-
## `matches`
45+
## `matches` <Badge type="tip" text="Requires WDL v1.2" />
4646

4747
Given two `String` parameters `input` and `pattern`, tests whether `pattern` matches
4848
`input` at least once. `pattern` is a [regular

0 commit comments

Comments
 (0)