CX · Reference guidedecision
PlaygroundDownloadsAboutv0.18.0-pre.1

decision

Bundled cx-stdlib module.

decision:decide

[$decision:decide] (table::element, inputs::map) -> any — The output record of a decision table for one map of inputs: the first matching rule's under hit=first, the one matching rule's under hit=unique, an array of every match's under hit=collect; the [default] when no rule matches; CXER0100 (E_DECISION_*) for no match and no default, two matches under unique, a table of the wrong shape or an input of the wrong kind — never null.

      [?lib 'cx-stdlib/decision' as=decision]
[$decision:decide [decision hit=first [input name=amount type=int] [output name=pct type=int] [rule [when [amount ge=100]] [then pct=10]] [default pct=0]] {amount: 150}]
    
      {pct: 10}
    

decision:validate

[$decision:validate] (table::element) -> any — The table when it is sound, else CXER0100 E_DECISION_INVALID naming every problem: the shape, the types, two rules that overlap under hit=unique and a gap under hit=first or unique with no [default], each with an input that shows it.

      [?lib 'cx-stdlib/decision' as=decision]
[?match [$decision:validate [decision hit=unique [input name=n type=int] [output name=o type=string] [rule [when [n ge=0]] [then o='non-negative']] [rule [when [n le=0]] [then o='non-positive']]]] [case [err @message=$m] $m] [else :sound]]
    
      'E_DECISION_INVALID: 1 problem(s) — overlap: rules 1 and 2 all match n=0 under hit=unique'