ViolationModule
PackageReified.Constraint
Inspects, traverses, and renders violations.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| conjoin | Violation.conjoin violations | Groups failures as a conjunction, returning None for no failures and the single failure unchanged for one. |
| alternatives | Violation.alternatives violations | Groups failures as rejected alternatives, returning None for no failures and the single failure unchanged for one. |
| children | Violation.children violation | The immediate children of a group, or an empty list for an atomic violation. |
| flatten | Violation.flatten violation | Every leaf of a violation tree, in report order. |
| tryExpectation | Violation.tryExpectation violation | The failing constraint's identity, when the violation is a single interpreted leaf. |
| tryActual | Violation.tryActual violation | The value that failed, when the violation is a single leaf carrying a portable one. |
| tryDescription | Violation.tryDescription violation | The author-supplied prose, when the violation is a single opaque leaf. |
| tryDescriptionKey | Violation.tryDescriptionKey violation | The author-supplied catalogue key, when the violation is a single opaque leaf carrying one. |
| render | Violation.render violation | Renders a violation as an English sentence fragment with no trailing punctuation, keeping conjunction and alternative groups distinct. |
| toMessageTree | Violation.toMessageTree violation | Projects a violation for an external localization system, preserving its grouping so a translator renders conjunctions and alternatives in their own word order. |
| renderWith | Violation.renderWith lookup violation | Renders a violation through a caller-supplied lookup, keeping the same grouping and separators render uses. |
| message | Violation.message renderer violation | Renders a violation as a localized predicate, with no attribute noun. |
| fullMessage | Violation.fullMessage renderer violation | Renders a violation as a complete sentence fragment, with the attribute noun composed once. |
Groups failures as a conjunction, returning
None for no failures and the single failure unchanged
for one.
Parameters
| Name | Type | Description |
|---|---|---|
| violations | Violation list |
Returns
Violation option
Verification Examples
[ first; second ] |> Violation.conjoin // Some (All (first, [ second ]))
Groups failures as rejected alternatives, returning
None for no failures and the single failure
unchanged for one.
Parameters
| Name | Type | Description |
|---|---|---|
| violations | Violation list |
Returns
Violation option
Verification Examples
[ first; second ] |> Violation.alternatives // Some (Any (first, [ second ]))The immediate children of a group, or an empty list for an atomic violation.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
Violation list
Every leaf of a violation tree, in report order.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
AtomicViolation list
Verification Examples
violation |> Violation.flatten |> List.lengthThe failing constraint's identity, when the violation is a single interpreted leaf.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
ConstraintAtom option
The value that failed, when the violation is a single leaf carrying a portable one.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
ConstraintValue option
The author-supplied prose, when the violation is a single opaque leaf.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
string option
The author-supplied catalogue key, when the violation is a single opaque leaf carrying one.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
MessageDescriptor option
Renders a violation as an English sentence fragment with no trailing punctuation, keeping conjunction and
alternative groups distinct.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
string
Verification Examples
Violation.render (Atomic (Expected (PresenceAtom Present, None)))
// "value must be present"
Projects a violation for an external localization system, preserving its grouping so a translator renders
conjunctions and alternatives in their own word order.
Parameters
| Name | Type | Description |
|---|---|---|
| violation | Violation |
Returns
MessageTree
Verification Examples
match Violation.toMessageTree violation with
| MessageTree.Leaf (MessageLeaf.Localized descriptor) -> MessageDescriptor.key descriptor
| _ -> "constraint.group"
Renders a violation through a caller-supplied lookup, keeping the same grouping and separators
render uses.
Parameters
| Name | Type | Description |
|---|---|---|
| lookup | MessageDescriptor -> string | |
| violation | Violation |
Returns
string
Verification Examples
violation |> Violation.renderWith (fun descriptor -> resources.Format(descriptor.Key, descriptor.Arguments))Renders a violation as a localized predicate, with no attribute noun.
Parameters
| Name | Type | Description |
|---|---|---|
| renderer | Renderer | |
| violation | Violation |
Returns
string
Verification Examples
violation |> Violation.message (renderer |> Renderer.context "signup" |> Renderer.attribute "name")
// "must be at least 13, but was 11"Renders a violation as a complete sentence fragment, with the attribute noun composed once.
Parameters
| Name | Type | Description |
|---|---|---|
| renderer | Renderer | |
| violation | Violation |
Returns
string
Verification Examples
violation |> Violation.fullMessage (signup |> Renderer.attribute "name")
// "Name must be present"