Skip to content

Commit bbe293b

Browse files
committed
feat(toSet): add toSet function
1 parent 1aec907 commit bbe293b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ export async function toArray<T>(iterable: AsyncIterableLike<T>): Promise<T[]> {
3434

3535
export const asyncToArray = toArray;
3636

37+
export async function toSet<T>(iterable: AsyncIterableLike<T>): Promise<Set<T>> {
38+
const set = new Set<T>();
39+
for await (const element of await iterable) {
40+
set.add(element);
41+
}
42+
return set;
43+
}
44+
45+
export const asyncToSet = toSet;
46+
3747
export async function first<T>(iterable: AsyncIterableLike<T>): Promise<T | null> {
3848
for await (const element of await iterable) {
3949
return element;

0 commit comments

Comments
 (0)