View Source Guesswork.Constraint protocol (Guesswork v0.8.0)

Represents a relationship between values that can be evaluated to produce or test new values.

Summary

Types

A simple value that indicates the result of a constraint.

t()

All the types that implement this protocol.

Functions

Applies the known values to the constraint, attempting to build a new value.

Displays the constraint in a human readable way. Opaque values should return nil.

Pulls all possible sets of inputs that could resolve the constraint.

Types

result()

@type result() :: :noanswer | :error | :ok | Guesswork.Constraint.Result.t()

A simple value that indicates the result of a constraint.

  • :error if the constraint is invalid.
  • :noanswer if the constraint cannot be resolved.
  • :ok if the constraint resolves to true.
  • %Guesswork.Constraint.Result{} if a new value has been derived. The last term indicates if the term should be negated.

t()

@type t() :: term()

All the types that implement this protocol.

Functions

apply(constraint, env)

@spec apply(t(), Guesswork.Ast.Statement.env()) :: result()

Applies the known values to the constraint, attempting to build a new value.

describe(constraint)

@spec describe(t()) :: String.t() | nil

Displays the constraint in a human readable way. Opaque values should return nil.

inputs(constraint)

@spec inputs(t()) :: [[Guesswork.Ast.Variable.t(), ...], ...]

Pulls all possible sets of inputs that could resolve the constraint.