Skip to content

Commit

Permalink
refactor(rstream-query): simplify transducer uses
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 8, 2018
1 parent cd5c6ff commit eb1714f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
20 changes: 9 additions & 11 deletions packages/rstream-query/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { isArray } from "@thi.ng/checks/is-array";
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
import { concat } from "@thi.ng/transducers/iter/concat";
import { pairs } from "@thi.ng/transducers/iter/pairs";
import { iterator } from "@thi.ng/transducers/iterator";
import { mapcat } from "@thi.ng/transducers/xform/mapcat";

let NEXT_ID = 0;
Expand All @@ -15,11 +14,11 @@ const mapBNode = (s: any, p: any, o: any) => {
const mapSubject = (subject: any) =>
([p, o]) => {
if (isArray(o)) {
return iterator(
mapcat((o) =>
return mapcat(
(o) =>
isPlainObject(o) ?
mapBNode(subject, p, o) :
[[subject, p, o]]),
[[subject, p, o]],
o);
} else if (isPlainObject(o)) {
return mapBNode(subject, p, o);
Expand Down Expand Up @@ -77,10 +76,9 @@ const mapSubject = (subject: any) =>
* @param subject internal use only, do not specify!
*/
export const asTriples = (obj: any, subject?: any) =>
iterator(
mapcat(
subject === undefined ?
([s, v]: any) => iterator(mapcat(mapSubject(s)), <any>pairs(v)) :
mapSubject(subject)
),
pairs(obj));
mapcat(
subject === undefined ?
([s, v]: any) => mapcat(mapSubject(s), <any>pairs(v)) :
mapSubject(subject),
pairs(obj)
);
5 changes: 2 additions & 3 deletions packages/rstream-query/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Reducer, Transducer } from "@thi.ng/transducers/api";
import { comp } from "@thi.ng/transducers/func/comp";
import { compR } from "@thi.ng/transducers/func/compr";
import { keySelector } from "@thi.ng/transducers/func/key-selector";
import { iterator } from "@thi.ng/transducers/iterator";
import { assocObj } from "@thi.ng/transducers/rfn/assoc-obj";
import { transduce } from "@thi.ng/transducers/transduce";
import { dedupe } from "@thi.ng/transducers/xform/dedupe";
Expand Down Expand Up @@ -397,8 +396,8 @@ export class TripleStore implements
}

protected addParamQueries(patterns: Iterable<Pattern>) {
return iterator(
map<Pattern, QuerySolution>((q) => this.addParamQuery(q)),
return map<Pattern, QuerySolution>(
(q) => this.addParamQuery(q),
patterns
);
}
Expand Down

0 comments on commit eb1714f

Please sign in to comment.