Skip to content

Commit

Permalink
feat: add a helper to check if any items match
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Mar 26, 2021
1 parent 313c4af commit 3f9403d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/listings/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,20 @@ export default class Listing<T> {
return true;
});
}

/**
* Determines whether the specified callback function returns true for any
* element of the listing.
*
* @param fn The matcher to run on each element. If this returns `true` at any
* point the searching is stopped.
*
* @returns A promise that resolves to `true` if `fn` returned `true` for some
* element in the listing, or `false` if it reached the end of the listing.
*/
async some(fn: Awaitable<T, boolean>): Promise<boolean> {
let found = false;
await this.each(async el => !(found = await fn(el)));
return found;
}
}

0 comments on commit 3f9403d

Please sign in to comment.