use of primal.persistent.PerSet in project suite by stupidsing.
the class Chr method chrThen.
private Streamlet<State> chrThen(Streamlet<State> states, Node then) {
var generalizer = new Generalizer();
Atom a = atom(".a"), b = atom(".b");
if (Binder.bind(then, generalizer.generalize(Suite.substitute(".0 = .1", a, b)))) {
// built-in syntactic equality
var from = generalizer.getVariable(a);
var to = generalizer.getVariable(b);
states = states.map(new Fun<>() {
public State apply(State state) {
var factsByPrototype1 = PerMap.<Prototype, PerSet<Node>>empty();
for (var e : state.factsByPrototype) factsByPrototype1 = factsByPrototype1.put(e.k, replace(e.v));
return new State(factsByPrototype1);
}
private PerSet<Node> replace(PerSet<Node> facts) {
var facts1 = PerSet.<Node>empty();
for (var node : facts) facts1 = facts1.replace(rw.replace(from, to, node));
return facts1;
}
});
}
return states.map(state -> {
var prototype = Prototype.of(then);
var facts = getFacts(state, prototype);
return setFacts(state, prototype, facts.replace(then));
});
}