Skip to content

pairwise

pairwise<T>(iterable): IterableIterator<[T, T]>

Defined in: packages/core/src/iterable/pairwise.ts:15

Yields each consecutive overlapping pair of elements.

The size = 2 case of windowed, kept separate so the result is a [T, T] tuple rather than a T[] a caller has to assert the width of.

An input of fewer than two elements yields nothing.

Time complexity: O(n), allocating one tuple per pair.

T

Iterable<T>

The input iterable.

IterableIterator<[T, T]>

An iterator over the pairs, each holding an element and the one after it.