xstream
Version:
An extremely intuitive, small, and fast functional reactive stream library for JavaScript
39 lines (38 loc) • 735 B
TypeScript
import { Stream } from '../index';
/**
* Group consecutive pairs of events as arrays. Each array has two items.
*
* Marble diagram:
*
* ```text
* ---1---2-----3-----4-----5--------|
* pairwise
* -------[1,2]-[2,3]-[3,4]-[4,5]----|
* ```
*
* Example:
*
* ```js
* import pairwise from 'xstream/extra/pairwise'
*
* const stream = xs.of(1, 2, 3, 4, 5, 6).compose(pairwise)
*
* stream.addListener({
* next: i => console.log(i),
* error: err => console.error(err),
* complete: () => console.log('completed')
* })
* ```
*
* ```text
* > [1,2]
* > [2,3]
* > [3,4]
* > [4,5]
* > [5,6]
* > completed
* ```
*
* @return {Stream}
*/
export default function pairwise<T>(ins: Stream<T>): Stream<[T, T]>;