/** * @since 0.1.8 */ import { Alt, Alt1, Alt2 } from 'fp-ts/lib/Alt' import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT' import { Monad, Monad1, Monad2 } from 'fp-ts/lib/Monad' import { Option } from 'fp-ts/lib/Option' /** * Execute an action repeatedly until the `Option` condition returns a `None`. Collects results into an arbitrary `Alt` * value, such as a `Array` or `NonEmptyArray`. * * @example * import { array } from 'fp-ts/Array' * import * as E from 'fp-ts/Either' * import { flow } from 'fp-ts/function' * import * as O from 'fp-ts/Option' * import * as TE from 'fp-ts/TaskEither' * import { collectUntil } from 'fp-ts-contrib/collectUntil' * * interface Page { * rows: Array * current_page: number * last_page: number * } * * // fake API * function fetchPage(current_page: number): TE.TaskEither { * if (current_page <= 3) { * return TE.right({ * rows: [`row1-Page${current_page}`, `row2-Page${current_page}`], * current_page: current_page, * last_page: 3 * }) * } else { * return TE.left('invalid page') * } * } * * const getNextInput = (page: Page): O.Option => * page.current_page < page.last_page ? O.some(page.current_page + 1) : O.none * * const collectRows = collectUntil( * TE.taskEither, * array * )( * flow( * fetchPage, * TE.map(page => [page.rows, getNextInput(page)]) * ) * ) * * collectRows(1)().then(rows => { * assert.deepStrictEqual( * rows, * E.right(['row1-Page1', 'row2-Page1', 'row1-Page2', 'row2-Page2', 'row1-Page3', 'row2-Page3']) * ) * }) * * @since 0.1.8 */ export declare function collectUntil( M: Monad2, F: Alt1 ): (f: (i: I) => Kind2, Option]>) => (i: I) => Kind2> export declare function collectUntil( M: Monad1, F: Alt2 ): (f: (i: I) => Kind, Option]>) => (i: I) => Kind> export declare function collectUntil( M: Monad1, F: Alt1 ): (f: (i: I) => Kind, Option]>) => (i: I) => Kind> export declare function collectUntil( M: Monad, F: Alt ): (f: (i: I) => HKT, Option]>) => (i: I) => HKT>