UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

26 lines (23 loc) 538 B
import { empty, 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<T>() { let previous: T | Empty = empty return new TransformStream<T, [T, T]>({ transform(chunk, controller) { if (previous !== empty) controller.enqueue([previous, chunk]) previous = chunk }, }) }