Skip to main content

differenceBy

differenceBy() function

Returns Iterable/AsyncIterable(i.e no duplicate) of all elements in the iterable2 not contained in the iterable1. Duplication is determined according to the value returned by applying the supplied f to iterable2.

Signature:
declare function differenceBy<A, B = unknown>(f: (a: A) => B, iterable1: Iterable<A>, iterable2: Iterable<A>): IterableIterator<A>;

declare function differenceBy<A, B = unknown>(f: (a: A) => B, iterable1: AsyncIterable<A>, iterable2: Iterable<A>): AsyncIterableIterator<A>;

declare function differenceBy<A, B = unknown>(f: (a: A) => B, iterable1: Iterable<A>, iterable2: AsyncIterable<A>): AsyncIterableIterator<A>;

declare function differenceBy<A, B = unknown>(f: (a: A) => B, iterable1: AsyncIterable<A>, iterable2: AsyncIterable<A>): AsyncIterableIterator<A>;

Example

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