Created
December 15, 2016 20:45
-
-
Save afs/2b8773d10cbe4bc1161e9851de02b3eb to your computer and use it in GitHub Desktop.
Box object to provide an apply capability.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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