ConstraintType
Creates, executes, composes, and inspects constraints.
Specification
Kind
Type
Members
64
Examples
0
satisfiesSignature
Constraint.satisfies constraint' value
checkSignature
Constraint.check constraint' value
guardSignature
Constraint.guard constraint' value
inspectSignature
Constraint.inspect constraint'
allSignature
Constraint.all constraints
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| satisfies | Constraint.satisfies constraint' value | Answers whether a value satisfies a constraint, without building a violation. |
| check | Constraint.check constraint' value | Runs a constraint, returning why the value failed. |
| guard | Constraint.guard constraint' value | Runs a constraint and returns the unchanged value after success. |
| inspect | Constraint.inspect constraint' | Returns the constraint's inspectable description. |
| all | Constraint.all constraints | Requires every constraint to hold, evaluating each in declaration order and accumulating failures. |
| any | Constraint.any first rest | Requires at least one alternative to hold, evaluating left to right and stopping at the first success. |
| notWith | Constraint.notWith description constraint' | Negates a constraint. |
| custom | Constraint.custom description predicate | Runs an arbitrary predicate, reporting the supplied prose when it fails. |
| customLocalized | Constraint.customLocalized key description predicate | Runs an arbitrary predicate, reporting the supplied prose and the author's own catalogue key when it fails. |
| customLocalizedWith | Constraint.customLocalizedWith key description arguments predicate | Runs an arbitrary predicate, reporting the supplied prose plus a catalogue key and named arguments a translation can interpolate. |
| customWith | Constraint.customWith description check | Runs an arbitrary callback that reports its own violation. |
| contramap | Constraint.contramap project constraint' | Applies a constraint to a projection of a larger value. |
| describe | Constraint.describe description constraint' | Attaches documentary prose to a constraint. |
| present | Constraint.present | Requires a value to be inhabited according to its shape. |
| blank | Constraint.blank | Requires a value to be uninhabited according to its shape; the exact complement of present. |
| optional | Constraint.optional inner | Lifts a constraint over an optional container: absence passes, presence runs the inner constraint. |
| length | Constraint.length expected | Requires text or a collection to have exactly the supplied size. |
| minLength | Constraint.minLength minimum | Requires text or a collection to have at least the supplied size. |
| maxLength | Constraint.maxLength maximum | Requires text or a collection to have at most the supplied size. |
| lengthBetween | Constraint.lengthBetween minimum maximum | Requires a text or collection size inside the supplied inclusive bounds. |
| single | Constraint.single | Requires a collection to hold exactly one item. |
| atLeastOne | Constraint.atLeastOne | Requires a collection to hold at least one item. |
| atMostOne | Constraint.atMostOne | Requires a collection to hold no more than one item. |
| moreThanOne | Constraint.moreThanOne | Requires a collection to hold two or more items. |
| emailPattern | Constraint.emailPattern | The exact regular expression Constraint.email runs. |
| numericPattern | Constraint.numericPattern | The exact regular expression Constraint.numeric runs. |
| nonBlankPattern | Constraint.nonBlankPattern | The regular expression an exporter may publish for Constraint.present on text. |
| trimmedPattern | Constraint.trimmedPattern | The regular expression an exporter may publish for Constraint.trimmed. |
| Constraint.email | Requires text to match Reified's pragmatic email shape, ^[^@]+@[^@]+$. | |
| trimmed | Constraint.trimmed | Requires text to have no leading or trailing whitespace. |
| numeric | Constraint.numeric | Requires text to be one or more ASCII digits. |
| alphanumeric | Constraint.alphanumeric | Requires text to be one or more letters or digits. |
| pattern | Constraint.pattern expression | Requires text to match the supplied .NET regular expression. |
| relationWith | Constraint.relationWith operator expected actual predicate | Builds a relation from an already-projected operand. |
| withinWith | Constraint.withinWith minimum maximum actual predicate | Builds an inclusive range from already-projected bounds. |
| oneOfWith | Constraint.oneOfWith choices actual predicate | Builds a membership rule from already-projected choices. |
| noneOfWith | Constraint.noneOfWith choices actual predicate | Builds an exclusion rule from already-projected choices. |
| checkBounds | Constraint.checkBounds name minimum maximum | Validates inclusive bounds. |
| equalTo | Constraint.equalTo expected | Requires equality with the supplied value, under F# structural equality. |
| notEqualTo | Constraint.notEqualTo unexpected | Requires inequality with the supplied value, under F# structural equality. |
| greaterThan | Constraint.greaterThan minimum | Requires a value strictly greater than the supplied bound. |
| lessThan | Constraint.lessThan maximum | Requires a value strictly less than the supplied bound. |
| atLeast | Constraint.atLeast minimum | Requires a value greater than or equal to the supplied bound. |
| atMost | Constraint.atMost maximum | Requires a value less than or equal to the supplied bound. |
| between | Constraint.between minimum maximum | Requires a value inside the supplied inclusive bounds. |
| positive | Constraint.positive | Requires a value strictly greater than zero. |
| nonNegative | Constraint.nonNegative | Requires a value of zero or greater. |
| negative | Constraint.negative | Requires a value strictly less than zero. |
| nonPositive | Constraint.nonPositive | Requires a value of zero or less. |
| oneOf | Constraint.oneOf choices | Requires the value to equal one of the supplied choices. |
| noneOf | Constraint.noneOf choices | Requires the value to equal none of the supplied choices. |
| containsWith | Constraint.containsWith expected values | Builds a containment rule from an already-projected item. |
| notContainsWith | Constraint.notContainsWith expected values | Builds an exclusion rule from an already-projected item. |
| uniquenessWith | Constraint.uniquenessWith item duplicate | Builds a uniqueness rule with a caller-supplied item projection. |
| containsIn | Constraint.containsIn expected values | The containment predicate. |
| excludesIn | Constraint.excludesIn expected values | The exclusion predicate. |
| firstDuplicate | Constraint.firstDuplicate values | The first-duplicate projection. |
| contains | Constraint.contains expected | Requires a collection to contain the supplied item. |
| notContains | Constraint.notContains expected | Requires a collection not to contain the supplied item. |
| distinct | Constraint.distinct | Requires a collection to hold no duplicates. |
| multipleOfWith | Constraint.multipleOfWith divisor actual predicate | Builds a divisibility rule from an already-projected divisor. |
| multipleOf | Constraint.multipleOf divisor | Requires an exact multiple of the supplied divisor, under the value type's own arithmetic. |
| finite | Constraint.finite | Requires a double to be neither infinite nor NaN. |
| finite32 | Constraint.finite32 | Requires a single-precision float to be neither infinite nor NaN. |
Operations
kind:member
Answers whether a value satisfies a constraint, without building a violation.
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'value> | |
| value | 'value |
Returns
bool
Verification Examples
let retryCount = Constraint.between 0 10
3 |> Constraint.satisfies retryCount // truekind:member
Runs a constraint, returning why the value failed.
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'value> | |
| value | 'value |
Returns
Result<unit, Violation>
Verification Examples
let retryCount = Constraint.between 0 10
42 |> Constraint.check retryCount |> Result.mapError Violation.renderkind:member
Runs a constraint and returns the unchanged value after success.
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'value> | |
| value | 'value |
Returns
Result<'value, Violation>
Verification Examples
let requiredName : Constraint<string> = Constraint.present
"Alice" |> Constraint.guard requiredName |> Result.mapError Violation.renderkind:member
Returns the constraint's inspectable description.
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'value> |
Returns
ConstraintDescription
Verification Examples
let requiredName : Constraint<string> = Constraint.present
(Constraint.inspect requiredName).Expressionkind:member
Requires every constraint to hold, evaluating each in declaration order and accumulating failures. The
empty list is the satisfied identity.
Parameters
| Name | Type | Description |
|---|---|---|
| constraints | Constraint<'value> list |
Returns
Constraint<'value>
Verification Examples
let requiredName : Constraint<string> =
Constraint.all [ Constraint.present; Constraint.lengthBetween 2 40 ]kind:member
Requires at least one alternative to hold, evaluating left to right and stopping at the first success. When
none succeeds, every rejected branch is reported.
Parameters
| Name | Type | Description |
|---|---|---|
| first | Constraint<'value> | |
| rest | Constraint<'value> list |
Returns
Constraint<'value>
Verification Examples
let ttl : Constraint<int> =
Constraint.any (Constraint.equalTo -1) [ Constraint.atLeast 1 ]kind:member
Negates a constraint. The result is opaque: it runs normally but cannot be exported or proved, and reports
the supplied prose.
Parameters
| Name | Type | Description |
|---|---|---|
| description | string | |
| constraint' | Constraint<'value> |
Returns
Constraint<'value>
Verification Examples
Constraint.notWith "must not be a reserved name" (Constraint.oneOf [ "admin"; "root" ])kind:member
Runs an arbitrary predicate, reporting the supplied prose when it fails.
Parameters
| Name | Type | Description |
|---|---|---|
| description | string | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
Verification Examples
let isValidIsbn (isbn: string) = isbn.Length = 13 in Constraint.custom "must be a valid ISBN" isValidIsbnkind:member
Runs an arbitrary predicate, reporting the supplied prose and the author's own catalogue key when it fails.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | |
| description | string | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
Verification Examples
let isValidIsbn (isbn: string) = isbn.Length = 13
in Constraint.customLocalized
"books.isbn.invalid"
"must be a valid ISBN"
isValidIsbnkind:member
Runs an arbitrary predicate, reporting the supplied prose plus a catalogue key and named arguments a
translation can interpolate.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | |
| description | string | |
| arguments | Map<string, ConstraintValue> | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
Verification Examples
let isValidIsbn (isbn: string) = isbn.Length = 13
in Constraint.customLocalizedWith
"books.isbn.invalid"
"must be a valid ISBN"
(Map.ofList [ "expectedLength", ConstraintValue.Integer 13L ])
isValidIsbnkind:member
Runs an arbitrary callback that reports its own violation.
Parameters
| Name | Type | Description |
|---|---|---|
| description | string | |
| check | 'value -> Result<unit, Violation> |
Returns
Constraint<'value>
Verification Examples
let supported = [ "USD"; "EUR" ] in Constraint.customWith "must be a supported currency" (Constraint.check (Constraint.oneOf supported))kind:member
Applies a constraint to a projection of a larger value.
Parameters
| Name | Type | Description |
|---|---|---|
| project | 'input -> 'value | |
| constraint' | Constraint<'value> |
Returns
Constraint<'input>
Verification Examples
Constraint.present |> Constraint.contramap (fun order -> order.Reference)kind:member
Attaches documentary prose to a constraint.
Parameters
| Name | Type | Description |
|---|---|---|
| description | string | |
| constraint' | Constraint<'value> |
Returns
Constraint<'value>
Verification Examples
Constraint.between 0 10 |> Constraint.describe "Retries before the call is abandoned."kind:member
kind:member
kind:member
Lifts a constraint over an optional container: absence passes, presence runs the inner constraint.
Parameters
| Name | Type | Description |
|---|---|---|
| inner | Constraint<'value> |
Returns
Constraint<^container>
Verification Examples
let nickname : Constraint<string option> =
Constraint.optional (Constraint.lengthBetween 2 40)kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Builds a relation from an already-projected operand. Not part of the supported surface.
Parameters
| Name | Type | Description |
|---|---|---|
| operator | RelationOperator | |
| expected | ConstraintValue option | |
| actual | 'value -> ConstraintValue option | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
kind:member
Builds an inclusive range from already-projected bounds. Not part of the supported surface.
Parameters
| Name | Type | Description |
|---|---|---|
| minimum | ConstraintValue option | |
| maximum | ConstraintValue option | |
| actual | 'value -> ConstraintValue option | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
kind:member
Builds a membership rule from already-projected choices. Not part of the supported surface.
Parameters
| Name | Type | Description |
|---|---|---|
| choices | ConstraintValue option list | |
| actual | 'value -> ConstraintValue option | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
kind:member
Builds an exclusion rule from already-projected choices. Not part of the supported surface.
Parameters
| Name | Type | Description |
|---|---|---|
| choices | ConstraintValue option list | |
| actual | 'value -> ConstraintValue option | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Builds a divisibility rule from an already-projected divisor. Not part of the supported surface.
Parameters
| Name | Type | Description |
|---|---|---|
| divisor | ConstraintValue option | |
| actual | 'value -> ConstraintValue option | |
| predicate | 'value -> bool |
Returns
Constraint<'value>
kind:member
kind:member