Skip to content

Instantly share code, notes, and snippets.

@afs
Created December 15, 2016 20:45
Show Gist options
  • Save afs/2b8773d10cbe4bc1161e9851de02b3eb to your computer and use it in GitHub Desktop.
Save afs/2b8773d10cbe4bc1161e9851de02b3eb to your computer and use it in GitHub Desktop.
Box object to provide an apply capability.
public static class Select extends Query implements Function<Dataset, ResultSet> {
public Select(String string) {
QueryFactory.parse(this, string, null, Syntax.syntaxARQ);
}
@Override
public ResultSet apply(Dataset t) {
return QueryExecutionFactory.create(this, t).execSelect();
}
}
static class Pipeline<T> {
public static <X> Pipeline<X> run(X x) { return new Pipeline<>(x); }
private T thing;
public Pipeline(T thing) { this.thing = thing ; }
public <R> Pipeline<R> apply(Function<T, R> f) { return Pipeline.run(f.apply(thing)) ; }
public void apply(Consumer<T> c) { c.accept(thing); }
}
public static void main(String ...args) {
Dataset dataset = DatasetFactory.create();
Function<Dataset, ResultSet> selectQuery = new Select("SELECT * { ?s ?p ?o}");
Consumer<ResultSet> rsp = (t)->ResultSetFormatter.out(t);
Pipeline.run(dataset).apply(selectQuery).apply(rsp) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment