import { pipe } from "../../../Function"; import type { Option } from "../../../Option"; import * as O from "../../../Option"; import type { Exit } from "../../Exit"; import * as Ex from "../../Exit"; import * as C from "../../Exit/Cause"; import * as T from "../../Task"; import type { Pull } from "./Pull"; export type Take = Exit, ReadonlyArray>; export const chunk = (as: ReadonlyArray): Take => Ex.succeed(as); export const halt = (cause: C.Cause): Take => Ex.failure(pipe(cause, C.map(O.some))); export const end: Take = Ex.fail(O.none()); export const done = (take: Take) => T.done(take); export const fromPull = (pull: Pull): T.Task> => pipe( pull, T.foldCause( (c) => pipe( C.sequenceCauseOption(c), O.fold(() => end, halt) ), chunk ) );