DataDSLModule
PackageReified.Data
Concise opt-in syntax for literals, immutable edits, cases, and matching.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| (=>) | name => value | Associates a field name with an exact value or recursive data pattern. |
| (?=>) | name ?=> value | Associates a field name with an optional exact value, omitting None. |
| nil | nil | An explicit structured null used by literals and edits. |
| num | num | Constructs an exact number from a validated portable JSON number token. |
| data | data | Builds an object from ordered field instructions. |
| fields | fields | Returns exact field instructions for spreading an existing object literal. |
| set | set path value | Replaces a value or adds a missing final object field. |
| replace | replace path value | Replaces an existing value. |
| remove | remove | Removes an existing field or list item. |
| append | append path value | Appends an item to an existing list. |
| prepend | prepend path value | Prepends an item to an existing list. |
| insert | insert path index value | Inserts an item at a valid list insertion index. |
| rename | rename | Renames an existing object field without moving it. |
| update | update | Applies an ordinary function to an existing value. |
| variant | variant name edits | Declares one named variation from a baseline. |
| variants | variants variations baseline | Materializes named variations from one baseline. |
| dimension | dimension name variations | Declares one named dimension in a Cartesian matrix. |
| matrix | matrix dimensions baseline | Materializes a deterministic Cartesian matrix, limited to 256 cases. |
| exactly | exactly value | Creates an exact recursive pattern. |
| containing | containing fields | Creates a partial object pattern from required fields. |
| containingItems | containingItems values | Matches expected items as an unordered consumed subset. |
| inOrder | inOrder values | Matches expected items as an ordered subsequence. |
| allItems | allItems value | Requires every actual list item to satisfy a pattern. |
| someItem | someItem value | Requires at least one actual list item to satisfy a pattern. |
| any | any | Matches any present value. |
| anyText | anyText | Matches any text value. |
| anyNumber | anyNumber | Matches any number token. |
| oneOf | oneOf patterns | Matches when one supplied alternative matches. |
| satisfying | satisfying description predicate | Matches an ordinary predicate and uses its description in diagnostics. |
| at | at path expected | Requires a path to contain an exact value or recursive pattern. |
| absent | absent path | Requires a path to be absent. |
| matching | matching expectations actual | Checks expectations or raises DataMatchException. |
Associates a field name with an exact value or recursive data pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | |
| value | ^value |
Returns
DataField
Associates a field name with an optional exact value, omitting
None.Parameters
| Name | Type | Description |
|---|---|---|
| name | string | |
| value | ^value option |
Returns
DataField
Constructs an exact number from a validated portable JSON number token.
Returns
string -> Data
Builds an object from ordered field instructions.
Returns
DataField list -> Data
Verification Examples
data [ "name" => "Ada"; "active" => true ]
// Data.Object [ "name", Data.Text "Ada"; "active", Data.Bool true ]Returns exact field instructions for spreading an existing object literal.
Returns
Data -> DataField list
Replaces a value or adds a missing final object field.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| value | ^a |
Returns
DataEdit
Replaces an existing value.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| value | ^a |
Returns
DataEdit
Appends an item to an existing list.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| value | ^a |
Returns
DataEdit
Prepends an item to an existing list.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| value | ^a |
Returns
DataEdit
Inserts an item at a valid list insertion index.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| index | int | |
| value | ^a |
Returns
DataEdit
Renames an existing object field without moving it.
Returns
string -> string -> DataEdit
Applies an ordinary function to an existing value.
Returns
string -> (Data -> Data) -> DataEdit
Declares one named variation from a baseline.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | |
| edits | DataEdit list |
Returns
DataVariation
Materializes named variations from one baseline.
Parameters
| Name | Type | Description |
|---|---|---|
| variations | DataVariation list | |
| baseline | Data |
Returns
DataCase list
Verification Examples
variants [ variant "inactive" [ replace "active" false ] ] (data [ "active" => true ])
// [ { Name = "inactive"; Value = data [ "active" => false ] } ]Declares one named dimension in a Cartesian matrix.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | |
| variations | DataVariation list |
Returns
DataDimension
Materializes a deterministic Cartesian matrix, limited to 256 cases.
Parameters
| Name | Type | Description |
|---|---|---|
| dimensions | DataDimension list | |
| baseline | Data |
Returns
DataCase list
Verification Examples
open Reified.DataDSL
let baseline = data [ "active" => true ]
matrix [ dimension "status" [ variant "active" []; variant "inactive" [ replace "active" false ] ] ] baseline
// cases named "status: active" and "status: inactive"Creates an exact recursive pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| value | ^a |
Returns
DataPattern
Creates a partial object pattern from required fields.
Parameters
| Name | Type | Description |
|---|---|---|
| fields | DataField list |
Returns
DataPattern
Verification Examples
Data.tryMatch [ at "" (containing [ "id" => 42 ]) ] (data [ "id" => 42; "extra" => true ])
// Ok ()Matches expected items as an unordered consumed subset.
Parameters
| Name | Type | Description |
|---|---|---|
| values | ^a list |
Returns
DataPattern
Verification Examples
open Reified.DataDSL
let actual = data [ "items" => [ "Ada"; "Grace"; "Mallory" ] ]
Data.tryMatch [ at "items" (containingItems [ "Ada"; "Grace" ]) ] actual
// Ok () when both values occur, in either orderMatches expected items as an ordered subsequence.
Parameters
| Name | Type | Description |
|---|---|---|
| values | ^a list |
Returns
DataPattern
Requires every actual list item to satisfy a pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| value | ^a |
Returns
DataPattern
Requires at least one actual list item to satisfy a pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| value | ^a |
Returns
DataPattern
Matches when one supplied alternative matches.
Parameters
| Name | Type | Description |
|---|---|---|
| patterns | DataPattern list |
Returns
DataPattern
Matches an ordinary predicate and uses its description in diagnostics.
Parameters
| Name | Type | Description |
|---|---|---|
| description | string | |
| predicate | Data -> bool |
Returns
DataPattern
Requires a path to contain an exact value or recursive pattern.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| expected | ^a |
Returns
DataExpectation
Requires a path to be absent.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string |
Returns
DataExpectation
Checks expectations or raises
DataMatchException.Parameters
| Name | Type | Description |
|---|---|---|
| expectations | DataExpectation list | |
| actual | Data |
Returns
unit
Verification Examples
open Reified.DataDSL
let actual = data [ "user" => data [ "name" => "Ada" ] ]
matching [ at "user.name" "Ada"; absent "error" ] actual
// returns unit when both expectations hold; otherwise raises DataMatchException