Skip to content

Commit

Permalink
added all
Browse files Browse the repository at this point in the history
  • Loading branch information
j50n committed Sep 15, 2023
1 parent 7a578d0 commit aff8b48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/enumerable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,32 @@ export class Enumerable<T> implements AsyncIterable<T> {
* @returns The first item that satisfies the testing function, or `undefined`.
*/
async find(
findFn: (item: T) => boolean | Promise<boolean>,
findFn: (element: T) => boolean | Promise<boolean>,
): Promise<T | undefined> {
for await (const item of this.iter) {
if (findFn(item)) {
return item;
for await (const element of this.iter) {
if (findFn(element)) {
return element;
}
}
return undefined;
}

/**
* Return `true` if every element satisfies the provided testing function.
* @param allFn The testing function.
* @returns `true` if every element satisfies the provided testing function.
*/
async all(
allFn: (element: T) => boolean | Promise<boolean>,
): Promise<boolean> {
for await (const element of this.iter) {
if (!allFn(element)) {
return false;
}
}
return true;
}

/**
* Count the number of items; optionally with a filter.
* @param filterFn Includes items where filter returns `true`.
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.20.41"}
{"version":"0.20.42"}

0 comments on commit aff8b48

Please sign in to comment.