UNPKG

@electric-sql/d2ts

Version:

D2TS is a TypeScript implementation of Differential Dataflow.

30 lines 1.06 kB
import { DifferenceStreamWriter } from '../graph.js'; import { StreamBuilder } from '../d2.js'; import { LinearUnaryOperator } from './base.js'; /** * Operator that applies a function to each element in the input stream */ export class MapOperator extends LinearUnaryOperator { #f; constructor(id, inputA, output, f, initialFrontier) { super(id, inputA, output, initialFrontier); this.#f = f; } inner(collection) { return collection.map(this.#f); } } /** * Applies a function to each element in the input stream * @param f - The function to apply to each element */ export function map(f) { return (stream) => { const output = new StreamBuilder(stream.graph, new DifferenceStreamWriter()); const operator = new MapOperator(stream.graph.getNextOperatorId(), stream.connectReader(), output.writer, f, stream.graph.frontier()); stream.graph.addOperator(operator); stream.graph.addStream(output.connectReader()); return output; }; } //# sourceMappingURL=map.js.map