import { toSet } from "https://deno.land/x/aitertools@0.4.0/mod.ts";
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));