Skip to content

Commit

Permalink
feat: add a helper to get the first item from a Listing
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed May 14, 2021
1 parent 87a53b0 commit 61e8e35
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/listings/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ export default class Listing<T> {
return false;
}

/**
* Get the first item of this listing.
*
* @returns A promise that resolves to either the first item of the listing,
* or `null` if the listing is empty.
*/
async first(): Promise<T | null> {
for await (const el of this) {
return el;
}

return null;
}

private static async nextPage<T>(
page: Listing<T>,
ctx: Context
Expand Down

0 comments on commit 61e8e35

Please sign in to comment.