diff --git a/packages/rstream-query/src/graph.ts b/packages/rstream-query/src/graph.ts index b87f6a2541..1e38b0dbf9 100644 --- a/packages/rstream-query/src/graph.ts +++ b/packages/rstream-query/src/graph.ts @@ -1,5 +1,4 @@ import { equiv } from "@thi.ng/api/equiv"; -// import { SortedMap } from "@thi.ng/associative/sorted-map"; import { intersection } from "@thi.ng/associative/intersection"; import { Stream, trace, Subscription, sync } from "@thi.ng/rstream"; import { Transducer, Reducer } from "@thi.ng/transducers/api"; @@ -60,15 +59,9 @@ export class FactGraph { } addQuery(id: string, [s, p, o]: Pattern) { - const qs: Subscription> = s != null ? - this.streamS.transform(indexSel(s), "s") : - this.streamAll.subscribe(null, "s"); - const qp: Subscription> = p != null ? - this.streamP.transform(indexSel(p), "p") : - this.streamAll.subscribe(null, "p"); - const qo: Subscription> = o != null ? - this.streamO.transform(indexSel(o), "o") : - this.streamAll.subscribe(null, "o"); + const qs: Subscription> = this.getIndexSelection(this.streamS, s, "s"); + const qp: Subscription> = this.getIndexSelection(this.streamP, p, "p"); + const qo: Subscription> = this.getIndexSelection(this.streamO, o, "o"); const results = sync, Set>({ id, src: [qs, qp, qo], @@ -111,6 +104,12 @@ export class FactGraph { } return -1; } + + protected getIndexSelection(stream: Stream, key: any, id: string): Subscription> { + return key != null ? + stream.transform(indexSel(key), id) : + this.streamAll.subscribe(null, id); + } } export const indexSel = (key: any): Transducer> =>