use of suite.util.FunUtil.Fun in project suite by stupidsing.
the class CompileProverImpl method prover.
@Override
public Prove_ prover(Node node) {
FunExpr rt = f.input();
Fun<FunExpr, ProveRt> cf = cps -> FunCreator.of(ProveRt.class, false).create(rt_ -> cps).apply(Map.ofEntries());
FunExpr compiled = new Object() {
private FunExpr compile_(Node node, FunExpr cps) {
return new //
SwitchNode<FunExpr>(//
node).match(".0, .1", m -> {
return compile_(m[0], compile_(m[1], cps));
}).match(".0; .1", m -> {
FunExpr cps1;
if (Boolean.TRUE) {
ProveRt proveRt_ = cf.apply(cps);
cps1 = f.object(proveRt_).invoke("test", rt);
} else
cps1 = cps;
FunExpr f0 = compile_(m[0], cps1);
FunExpr f1 = compile_(m[1], cps1);
return f.seq(f0, f1);
}).match("fail", m -> {
return f._void();
}).match("yes", m -> {
return cps;
}).nonNullResult();
}
}.compile_(node, rt.fieldSet("ok", ok));
ProveRt proveRt = cf.apply(compiled);
return proverConfig -> {
Runtime_ rt_ = new Runtime_();
rt_.proverConfig = proverConfig;
proveRt.test(rt_);
return rt_.ok;
};
}
use of suite.util.FunUtil.Fun in project suite by stupidsing.
the class SewingProverBuilder method build.
@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
ProverFactory sewingProver = new SewingProverImpl(ruleSet);
return goal -> {
Node goal1 = SewingGeneralizerImpl.generalize(goal);
Prove_ pred = sewingProver.prover(goal1);
return (source, sink) -> {
ProverConfig proverConfig1 = new ProverConfig(ruleSet, proverConfig);
proverConfig1.setSource(source);
proverConfig1.setSink(sink);
pred.test(proverConfig1);
};
};
}
use of suite.util.FunUtil.Fun in project suite by stupidsing.
the class Chr method chrIf.
private Streamlet<State> chrIf(Streamlet<State> states, Trail trail, Node if_) {
Prototype prototype = Prototype.of(if_);
Fun<State, Streamlet<State>> fun = state -> {
ISet<Node> facts = getFacts(state, prototype);
Predicate<Node> bindFun = bindFun(trail, if_);
return facts.streamlet().filter(bindFun).map(node -> setFacts(state, prototype, facts.remove(node)));
};
return states.concatMap(fun);
}
use of suite.util.FunUtil.Fun in project suite by stupidsing.
the class Trade_ method dividend.
public static float dividend(Streamlet<Trade> trades, Fun<String, LngFltPair[]> fun, Dbl_Dbl feeFun) {
float sum = 0f;
for (Pair<String, List<Trade>> pair : trades.toMultimap(trade -> trade.symbol).listEntries()) {
LngFltPair[] dividends = fun.apply(pair.t0);
Outlet<Trade> outlet = Outlet.of(pair.t1);
LngIntPair tn = LngIntPair.of(0l, 0);
Source<LngIntPair> tradeSource = () -> {
Trade trade = outlet.next();
long t = trade != null ? Time.of(trade.date + " 12:00:00").epochSec(8) : Long.MAX_VALUE;
return LngIntPair.of(t, tn.t1 + (trade != null ? trade.buySell : 0));
};
LngIntPair tn1 = tradeSource.source();
for (LngFltPair dividend : dividends) {
while (tn1 != null && tn1.t0 < dividend.t0) {
tn.update(tn1.t0, tn1.t1);
tn1 = tradeSource.source();
}
float amount = tn.t1 * dividend.t1;
sum += amount - feeFun.apply(amount);
}
}
return sum;
}
use of suite.util.FunUtil.Fun in project suite by stupidsing.
the class DblFunUtil method suck.
/**
* Sucks data from a sink and produce into a source.
*/
public static DblSource suck(Sink<DblSink> fun) {
NullableSyncQueue<Double> queue = new NullableSyncQueue<>();
DblSink enqueue = c -> enqueue(queue, c);
Thread thread = Thread_.startThread(() -> {
try {
fun.sink(enqueue);
} finally {
enqueue(queue, EMPTYVALUE);
}
});
return () -> {
try {
return queue.take();
} catch (InterruptedException ex) {
thread.interrupt();
return Fail.t(ex);
}
};
}
Aggregations