decisions/fact
Typed fact keys. A fact’s name and type are declared once, as a key.
A point declares the facts a policy may read with the key
(decisions.fact and decisions.signal), a policy written in Gleam
builds its conditions with the same key (decisions/policy.below and
the others), and a model reports its signals with set. A misspelt
name, or a number rule on a text fact, then does not compile. A policy
that arrives as stored data is checked against the point’s declared
keys by decisions.publishable.
import decisions/fact
pub fn amount() -> fact.Key(Float) {
fact.number("amount")
}
let signals = [fact.set(amount(), 80.0)]
Target-independent: builds for Erlang and JavaScript.
Types
Values
pub fn get(
facts: List(#(String, vocabulary.Fact)),
key: Key(a),
) -> Result(a, Nil)
The value of this key among facts. Error(Nil) when it is absent or
has another type.
pub fn number(name: String) -> Key(Float)
A key for a number, such as an amount or a score.
pub fn set(key: Key(a), value: a) -> #(String, vocabulary.Fact)
One named fact, for a model’s signals or a consulted point’s answer.
pub fn text(name: String) -> Key(String)
A key for a text, such as an environment or a category.
pub fn waited_minutes() -> Key(Float)
The fact the library supplies to every policy: whole minutes since the recommendation. A rule that reads it makes a policy change its answer as an occurrence waits, which is how escalation and “proceed if nobody objects within the hour” are written. A point never declares it.
pub fn wrap(key: Key(a), value: a) -> vocabulary.Fact
The fact value as stored, for building a condition over it.