toSet<T>(source: AsyncIterable<T>): Promise<Set<T>>
Creates a set from an async iterable.
import { toSet } from "./collections.ts"; async function* gen() { yield "foo"; yield "bar"; yield "baz"; } const set = await toSet(gen());
The set variable will be a set like new Set(["foo", "bar", "baz"]).
Duplicate elements are removed except for the first occurrence of each element. E.g.:
import { toSet } from "./collections.ts"; async function* gen() { yield "foo"; yield "bar"; yield "foo"; } const set = await toSet(gen());
The set variable will be a set like new Set(["foo", "bar"]).
Note that the iterable source is assumed to be finite; otherwise, it will
never return. The following example will never return:
import { toSet } from "./collections.ts"; import { count } from "./infinite.ts"; await toSet(count(0));
source: AsyncIterable<T>
An async iterable to create a set from. It must be finite.