Skip to content

Commit

Permalink
revise: more updates to stdlib
Browse files Browse the repository at this point in the history
* Adds some designations of WDL v1.2 functions.
* Adds String Array functions.
  • Loading branch information
claymcleod committed Feb 5, 2025
1 parent 32df4d2 commit a30946e
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export default defineConfig({
text: "File functions",
link: "/reference/stdlib/file",
},
{
text: "String Array functions",
link: "/reference/stdlib/string-array",
},
],
collapsed: true,
},
Expand Down
5 changes: 2 additions & 3 deletions reference/stdlib/file.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# File Functions

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


**Signatures**

```wdl
Expand Down Expand Up @@ -60,7 +59,7 @@ String bn = basename("/path/to/file.txt", ".txt")
# `bn` contains `"file"`.
```

## `join_paths`
## `join_paths` <Badge type="tip" text="Requires WDL v1.2" />

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

Expand Down
148 changes: 148 additions & 0 deletions reference/stdlib/string-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# String Array Functions

- [`prefix`](#prefix)
- [`suffix`](#suffix)
- [`quote`](#quote)
- [`squote`](#squote)
- [`sep`](#sep)

## `prefix`

Adds a prefix to each element of the input array of primitive values. Equivalent to
evaluating `"~{prefix}~{array[i]}"` for each `i` in `range(length(array))`.

**Signatures**

```wdl
Array[String] prefix(String, Array[P])
```

**Parameters**

1. **`String`**: The prefix to prepend to each element in the array.
2. **`Array[P]`**: Array with a primitive element type.

**Returns**

1. An `Array[String]` with the prefixed elements of the input array.

**Example**

```wdl
Array[String] names = ["John", "Jane", "world"]
String greetings = prefix("Hello, ", names)
# `greetings` now contains `["Hello, John", "Hello, Jane", "Hello, world"]`.
```

## `suffix`

Adds a suffix to each element of the input array of primitive values. Equivalent to
evaluating `"~{array[i]}~{suffix}"` for each `i` in `range(length(array))`.

**Signatures**

```wdl
Array[String] suffix(String, Array[P])
```

**Parameters**

1. **`String`**: The suffix to append to each element in the array.
2. **`Array[P]`**: Array with a primitive element type.

**Returns**

1. An `Array[String]` the suffixed elements of the input array.

**Example**

```wdl
Array[String] names = ["John", "Jane"]
String responses = suffix(" says 'hi!'", names)
# `responses` now contains `["John says 'hi!'", "Jane says 'hi!'"]`.
```

## `quote`

Adds double-quotes (`"`) around each element of the input array of primitive values.
Equivalent to evaluating `'"~{array[i]}"'` for each `i` in `range(length(array))`.

**Signatures**

```wdl
Array[String] quote(Array[P])
```

**Parameters**

1. **`Array[P]`**: Array with a primitive element type.

**Returns**

1. An `Array[String]` the double-quoted elements of the input array.

**Example**

```wdl
Array[String] numbers = [1, 2, 3]
String quoted = quote(numbers)
# `quoted` now contains `["\"1\"", "\"2\"", "\"3\""]`.
```

## `squote`

Adds single-quotes (`'`) around each element of the input array of primitive values.
Equivalent to evaluating `"'~{array[i]}'"` for each `i` in `range(length(array))`.

**Signatures**

```wdl
Array[String] squote(Array[P])
```

**Parameters**

1. **`Array[P]`**: Array with a primitive element type.

**Returns**

1. An `Array[String]` the single-quoted elements of the input array.

**Example**

```wdl
Array[String] numbers = [1, 2, 3]
String quoted = squote(numbers)
# `quoted` now contains `["'1'", "'2'", "'3'"]`.
```

## `sep`

Concatenates the elements of an array together into a string with the given separator
between consecutive elements. There are always `N-1` separators in the output string,
where `N` is the length of the input array. A separator is never added after the last
element. Returns an empty string if the array is empty.

**Signatures**

```wdl
String sep(String, Array[P])
```

**Parameters**

1. `String`: Separator string.
2. `Array[P]`: Array of strings to concatenate.

**Returns**

1. A `String` with the concatenated elements of the array delimited by the separator
string.

**Example**

```wdl
Array[String] letters = ["a", "b", "c", "d"]
String letters_with_commas = sep(", ", letters)
# `letters_with_commas` now contains `"a, b, c, d"`.
```
8 changes: 4 additions & 4 deletions reference/stdlib/string.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# String Functions

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

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

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

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

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

0 comments on commit a30946e

Please sign in to comment.