Effectful Evaluation
Decisions4s
allows evaluating a decision based on effectful inputs, e.g., when network call is required for a
particular piece of data.
- Inputs will be executed at most once (memoized).
- Inputs will be executed only if required by the rule.
- Input is considered not required if
catchAll
expression is used for matching. - Table needs to use
HitPolicy.First
because it's the only one for which lazy evaluation can be expected.
To use that feature, add an additional dependency.
"org.business4s" %% "decisions4s-cats-effect" % "0.0.1"
import cats.effect.IO
import decisions4s.*
import decisions4s.cats.effect.*
val decisionTable: DecisionTable[Input, Output, HitPolicy.First] = ???
val input: Input[IO] = ???
decisionTable.evaluateFirstF(input).map(_.output)
Other Effect Systems
As of now only cats-effect
is supported, but the same can be achieved for any other effect system or even () => T
.
If you want to give it a try and need assistance, please reach out on Discord.