Skip to content

deltas

deltas<T, D>(iterable, subtract): IterableIterator<D>

Defined in: packages/core/src/iterable/deltas.ts:23

Yields the difference between each element and the one before it.

subtract is required rather than defaulting to numeric subtraction: the operation is the caller’s, which is what keeps this out of the math packages — nothing here computes on numbers, it only applies what it is given.

Arguments reach subtract as (current, previous), so numeric subtraction makes an increase positive.

An input of fewer than two elements yields nothing, so there is always one fewer delta than there are elements.

Time complexity: O(1) per element, plus whatever subtract costs.

T

D

Iterable<T>

The input iterable.

Callable<[T, T], D>

Computes the difference between an element and its predecessor.

IterableIterator<D>

An iterator over the consecutive differences.