You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You do not need to create a new RuleBook each time you run it. RuleBooks can, however, change facts. So, if you rerun the same facts in a RuleBook multiple times, then you could certainly get a different state after subsequent runs.
Taking a modified version of your example:
NameValueReferableMap<Integer> facts = newFactMap<>();
facts.setValue("Steve", 30);
facts.setValue("Eddie", 42);
facts.setValue("Mary", 32);
RuleBookruleBook = RuleBookBuilder.create().addRule(rule -> rule.withFactType(Integer.class)
.then(people -> people.entrySet().stream()
.map(entry -> entry.getValue()) //map entries to people Facts
.filter(person -> person.getValue() < 40) //filter out people Facts for those who are under 40
.map(person -> person.getName()) //map people to their names
.forEach(System.out::println))) //print the names of the people
.build();
ruleBook.run(facts);
ruleBook.run(facts);
RuleBooks accept data as Facts, which can also be created or manipulated within a Rule. A Rule is provided all of the matching facts as an input. So, whereas the above example that I provided from your example does work, it's probably not the best use case for RuleBook. Something more akin to the MegaBank example, the POJO MegaBank Example or another scenario where there are different facts that determine whether or not an action should be taken is probably a better scenario.
Anyway, to your question about having to create a new RuleBook for each run: In the example I used above, the RuleBook I created is run twice from the same instance. In both cases the results are:
Steve
Mary
I understand one can apply multiple rules to any value on the facts map.
But what if I have a List of objects that I want to have evaluated by the same rule pipeline?
Imagine I have something like:
It seems that if I want to put a List/Set of objects through a rule pipeline at the moment I always need to recreate a new Rulebook, is this right?
The text was updated successfully, but these errors were encountered: