BehaviorDsl
Behavior DSL (pure)
Minimal DSL to build decision logic:
- PartialBehavior =
Kleisli[Option, I, A]
– a partial decision (“may produce”). - Behavior =
Kleisli[Id, I, A]
– a total decision (“always produces”).
Partial behaviors compose left-biased (the first Some
wins) and are finalized into total behaviors via orElse (or the compatibility alias default).
Attributes
- Example
-
val isEven: Condition[Int] = _ % 2 == 0 val rule: PartialBehavior[Int, String] = (isEven ==> "even") | (_ => true) ==> "odd" val behavior: Behavior[Int, String] = rule.orElse("n/a") behavior.run(2) // "even" behavior.run(3) // "odd"
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
BehaviorDsl.type
Members list
Extensions
Extensions
Logical AND of two conditions.
Logical AND of two conditions.
Value parameters
- d
-
condition to combine with
Attributes
- Returns
-
a condition that holds only if both
c
andd
hold
Logical NOT of a condition.
Logical NOT of a condition.
Attributes
- Returns
-
a condition that holds when
c
does not hold
Logical OR of two conditions.
Logical OR of two conditions.
Value parameters
- d
-
condition to combine with
Attributes
- Returns
-
a condition that holds if either
c
ord
holds
Build a partial behavior from a condition.
Build a partial behavior from a condition.
Produces Some(act)
when the condition holds; otherwise None
. The action is call-by-name and evaluated only if needed.
Value parameters
- act
-
action to produce when the condition holds (lazy)
Attributes
- Returns
-
a PartialBehavior that yields
Some(act)
ifcond(i)
is true, elseNone
Gate this partial behavior with an additional predicate.
Gate this partial behavior with an additional predicate.
When p(i)
is false, this rule forcibly defers (None
).
Value parameters
- p
-
additional predicate on the same input
Attributes
- Returns
-
a PartialBehavior that runs only if
p
holds
Finalize a partial behavior into a total behavior by providing a fallback.
Finalize a partial behavior into a total behavior by providing a fallback.
If the composed partial chain yields None
, the fallback is used.
Value parameters
- fallback
-
default action to use when no rule fires (lazy)
Attributes
- Returns
-
a total Behavior that always produces an action
Left-biased composition of two partial behaviors.
Left-biased composition of two partial behaviors.
Evaluates r1(i)
: if it returns Some(a)
the result is kept, otherwise r2(i)
is evaluated.
Value parameters
- r2
-
fallback partial behavior to try when
r1
defers
Attributes
- Returns
-
a PartialBehavior that prefers
r1
overr2