UNPKG

@codibre/fluent-iterable

Version:

Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).

22 lines (21 loc) 739 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Translate a paginated resource into a non-paginated iterable of elements. * @typeparam T The type of the elements of the page. * @typeparam TToken The type of the next page token associated to the page. * @param pager Represents the way of retrieving pages from the paginated resource. * @returns The iterable representing a steady flow of elements from the paginated resource. */ async function* depaginate(pager) { let token; do { const page = await pager(token); if (!page) { break; } yield* page.results; token = page.nextPageToken; } while (token); } exports.default = depaginate;