@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
25 lines • 587 B
JavaScript
import { empty } from '@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]--
* ```
*/
export function pairwise() {
let previous = empty;
return new TransformStream({
transform(chunk, controller) {
if (previous !== empty)
controller.enqueue([previous, chunk]);
previous = chunk;
},
});
}
//# sourceMappingURL=pairwise.js.map