@electric-sql/d2mini
Version:
D2Mini is a minimal implementation of Differential Dataflow for performing in-memory incremental view maintenance.
30 lines • 1 kB
JavaScript
import { DifferenceStreamWriter } from '../graph.js';
import { StreamBuilder } from '../d2.js';
import { LinearUnaryOperator } from '../graph.js';
/**
* Operator that applies a function to each element in the input stream
*/
export class MapOperator extends LinearUnaryOperator {
#f;
constructor(id, inputA, output, f) {
super(id, inputA, output);
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.addOperator(operator);
stream.graph.addStream(output.connectReader());
return output;
};
}
//# sourceMappingURL=map.js.map