import type { Either } from "../Either"; import * as E from "../Either"; import type { FunctionN, Lazy } from "../Function"; import type { IO } from "../IO"; import * as X from "../XPure"; import type { EIO } from "./model"; /* * ------------------------------------------- * EIO Constructors * ------------------------------------------- */ export const fail: (e: E) => EIO = X.fail; export const succeed: (a: A) => EIO = X.succeed; export const total: (thunk: () => A) => EIO = X.total; export const leftIO: (io: IO) => EIO = X.chain(fail); export const rightIO: (io: IO) => EIO = X.chain(succeed); export const fromEither: (pab: Either) => EIO = E.fold(fail, succeed); export const _partial: (thunk: Lazy, onThrow: (reason: unknown) => E) => EIO = X.partial_; export const partial = (onThrow: (reason: unknown) => E) => (thunk: Lazy) => _partial(thunk, onThrow); export const _partialK = , B, E>( f: FunctionN, onThrow: (reason: unknown) => E ): ((...args: A) => EIO) => (...a) => _partial(() => f(...a), onThrow); export const partialK = (onThrow: (reason: unknown) => E) => , B>( f: FunctionN ) => _partialK(f, onThrow);