hydra.lib.flows.Fail Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hydra-java Show documentation
Show all versions of hydra-java Show documentation
The Hydra language for strongly-typed transformations
package hydra.lib.flows;
import hydra.Flows;
import hydra.compute.Flow;
import hydra.compute.FlowState;
import hydra.core.Name;
import hydra.core.Term;
import hydra.core.Type;
import hydra.dsl.Terms;
import hydra.dsl.Types;
import hydra.graph.Graph;
import hydra.lib.lists.Cons;
import hydra.tools.PrimitiveFunction;
import java.util.List;
import java.util.function.Function;
import static hydra.dsl.Terms.app;
import static hydra.dsl.Terms.flowState;
import static hydra.dsl.Terms.lambda;
import static hydra.dsl.Terms.project;
import static hydra.dsl.Terms.unwrap;
import static hydra.dsl.Terms.variable;
public class Fail extends PrimitiveFunction {
public Name name() {
return new Name("hydra/lib/flows.fail");
}
@Override
public Type type() {
return Types.lambda("s", "x", Types.function(Types.string(), Types.flow("s", "x")));
}
@Override
protected Function, Flow> implementation() {
return args -> Flows.pure(app(unwrap(Flow.NAME), lambda("q", flowState(
Terms.nothing(),
app(project(FlowState.NAME, "state"), variable("q")),
app((new Cons().term()), args.get(0), app(project(FlowState.NAME, "trace"), variable("q")))))));
}
public static Flow apply(String msg) {
return Flows.fail(msg);
}
}