UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

29 lines 735 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pairwise = void 0; const Symbol_1 = require("@johngw/stream-common/Symbol"); /** * Puts the current value and previous value together as an array, and queues that. * * @group Transformers * @example * ``` * --a----b------c------d------ * * pairwise() * * -------[a,b]--[b,c]--[c,d]-- * ``` */ function pairwise() { let previous = Symbol_1.empty; return new TransformStream({ transform(chunk, controller) { if (previous !== Symbol_1.empty) controller.enqueue([previous, chunk]); previous = chunk; }, }); } exports.pairwise = pairwise; //# sourceMappingURL=pairwise.js.map