Home > polyethylene > PolyAsyncIterable > unique
Return an iteration of unique elements, where two elements are considered equal if the result of func(element)
is the same for both elements.
Signature:
unique(func?: AsyncIndexedMapping<T, unknown>): PolyAsyncIterable<T>;
Parameter | Type | Description |
---|---|---|
func | AsyncIndexedMapping<T, unknown> | A function that returns a _key_ used for uniqueness checks. If not passed, an identitity function is used. |
Returns:
PolyAsyncIterable<T>
A new PolyAsyncIterable only elements for which func(element)
returns a value that hasn't been seen before
Note that the first element seen with a specific key is always the one yielded, and every other element afterwards is ignored.
If no key-mapping function is given, the elements theselves are used as keys. This is likely _not_ what you want in most situations unless elements are primitive types.