Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion docs/_openvox_8x/lang_data_abstract.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
[hash_missing_key_access]: ./lang_data_hash.html#accessing-values
[numbers]: ./lang_data_number.html

As described in [the Data Type Syntax][types] page, each of Puppet's main [data types][] has a corresponding value that _represents_ that data type, which can be used to match values of that type in several contexts. (For example, `String` or `Array`.)

Check failure on line 16 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Line length

docs/_openvox_8x/lang_data_abstract.md:16:211 MD013/line-length Line length [Expected: 210; Actual: 252] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md013.md

Each of those core data types will only match a particular set of values. They let you further restrict the values they'll match, but only in limited ways, and there's no way to _expand_ the set of values they'll match.

Check failure on line 18 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Line length

docs/_openvox_8x/lang_data_abstract.md:18:211 MD013/line-length Line length [Expected: 210; Actual: 219] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md013.md

If you're using data types to match or restrict values and need more flexibility, you can use one of the _abstract data types_ on this page to construct a data type that suits your needs and matches the values you want.

Check failure on line 20 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Line length

docs/_openvox_8x/lang_data_abstract.md:20:211 MD013/line-length Line length [Expected: 210; Actual: 219] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md013.md


Check failure on line 22 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Multiple consecutive blank lines

docs/_openvox_8x/lang_data_abstract.md:22 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md
## Flexible data types

These abstract data types can match values with a variety of concrete data types. Some of them are similar to a concrete type but offer alternate ways to restrict them (like `Enum`), and some of them let you combine types and match a union of what they would individually match (like `Variant` and `Optional`).

Check failure on line 25 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Line length

docs/_openvox_8x/lang_data_abstract.md:25:211 MD013/line-length Line length [Expected: 210; Actual: 310] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md013.md

### `Optional`

Expand All @@ -38,8 +38,8 @@

Optional[<DATA TYPE>]

Position | Parameter | Data Type | Default Value | Description

Check failure on line 41 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Table column style

docs/_openvox_8x/lang_data_abstract.md:41:29 MD060/table-column-style Table column style [Table pipe has extra space to the left for style "compact"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md

Check failure on line 41 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Table pipe style

docs/_openvox_8x/lang_data_abstract.md:41:69 MD055/table-pipe-style Table pipe style [Expected: compact; Actual: no_leading_or_trailing; Missing trailing pipe] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md055.md

Check failure on line 41 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Table pipe style

docs/_openvox_8x/lang_data_abstract.md:41:1 MD055/table-pipe-style Table pipe style [Expected: compact; Actual: no_leading_or_trailing; Missing leading pipe] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md055.md
---------| -----------------|-----------|---------------|------------

Check failure on line 42 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Table pipe style

docs/_openvox_8x/lang_data_abstract.md:42:69 MD055/table-pipe-style Table pipe style [Expected: compact; Actual: no_leading_or_trailing; Missing trailing pipe] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md055.md

Check failure on line 42 in docs/_openvox_8x/lang_data_abstract.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Table pipe style

docs/_openvox_8x/lang_data_abstract.md:42:1 MD055/table-pipe-style Table pipe style [Expected: compact; Actual: no_leading_or_trailing; Missing leading pipe] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md055.md
1 | Data type | `Type` or `String` | none **(mandatory)** | The data type to add `undef` to.

`Optional` also allows you to specify a string as its parameter, which is a shortcut for `Optional[Enum["my string"]]` --- it will match only that exact string value or `undef`.
Expand Down Expand Up @@ -282,7 +282,6 @@

The `Any` data type matches _any_ value of _any_ data type.


## Unusual types

These types aren't quite like the others.
Expand All @@ -308,3 +307,36 @@
-2 | Max count | `Integer` | infinity | The maximum number of arguments the lambda accepts. This parameter accepts the special value `default`, which will use its default value.
-1 | Block type | `Type[Callable]` | none | The `block_type` of the lambda.

### `Init`

The `Init` data type matches values that can be used as the initialization/typecase of another data type given as a parameter. This can be used to test if a value can be converted to the wanted data type.

#### Parameters

The signature for `Init` is:

Init[ <DATA TYPE> ]

#### Examples

Check if a string value can be converted to a `SemVer`:

``` puppet
"1.2.3" =~ Init[SemVer] # result is true
"latest" =~ Init[SemVer] # result is false
```

Check if a value can be converted to an `Integer`:

```
"10" =~ Init[Integer] # result is true
"blue" =~ Init[Integer] # result is false
```

Accept a parameter value that is either an `Integer` or a value convertible to one:

``` puppet
function example(Variant[Integer, Init[Integer]] $x) {
$int_value = Integer($x) # Safe conversion
}
```