Skip to main content
Home

Built and signed on GitHub Actions

Well-tested utility functions dealing with async iterables

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
2 years ago (0.6.0)
function toSet
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));

Type Parameters

The type of the elements in the source and the returned set.

Parameters

source: AsyncIterable<T>

An async iterable to create a set from. It must be finite.

Return Type

A set that contains the elements from the source iterable. Duplicate elements are removed except for the first one.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";
or

Import directly with a jsr specifier

import { toSet } from "jsr:@hongminhee/aitertools";

Add Package

pnpm i jsr:@hongminhee/aitertools
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";

Add Package

yarn add jsr:@hongminhee/aitertools
or (using Yarn 4.8 or older)
yarn dlx jsr add @hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";

Add Package

vlt install jsr:@hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";

Add Package

npx jsr add @hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";

Add Package

bunx jsr add @hongminhee/aitertools

Import symbol

import { toSet } from "@hongminhee/aitertools";