Skip to main content

difference

difference() function

Returns Iterable/AsyncIterable of all elements in the iterable2 not contained in the iterable1.

Signature:
declare function difference<T>(iterable1: Iterable<T>, iterable2: Iterable<T>): IterableIterator<T>;

declare function difference<T>(iterable1: AsyncIterable<T>, iterable2: Iterable<T>): AsyncIterableIterator<T>;

declare function difference<T>(iterable1: Iterable<T>, iterable2: AsyncIterable<T>): AsyncIterableIterator<T>;

declare function difference<T>(iterable1: AsyncIterable<T>, iterable2: AsyncIterable<T>): AsyncIterableIterator<T>;

declare function difference<A extends Iterable<unknown> | AsyncIterable<unknown>, B extends Iterable<unknown> | AsyncIterable<unknown>>(iterable1: A): (iterable2: B) => A extends AsyncIterable<unknown> ? AsyncIterableIterator<IterableInfer<B>> : B extends AsyncIterable<unknown> ? AsyncIterableIterator<IterableInfer<B>> : IterableIterator<IterableInfer<B>>;

Example

const iter = difference([2, 1], [2, 3, 4]);
iter.next(); // {value: 3, done:false}
iter.next(); // {value: 4, done:false}
iter.next(); // {value: undefined, done: true}

Open Source Code