UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

114 lines 3.29 kB
/** * Utility functions to accommodate `fp-ts/IOEither`. * * @since 0.15.0 */ import type { IOEither } from "fp-ts/IOEither"; import type { Show } from "fp-ts/Show"; /** * Unwrap the value from within an `IOEither`, throwing with the inner value of * `Left` if `Left`. * * @example * import { unsafeUnwrap } from 'fp-ts-std/IOEither' * import * as IOE from 'fp-ts/IOEither' * * assert.strictEqual(unsafeUnwrap(IOE.right(5)), 5) * * @category 3 Functions * @since 0.15.0 */ export declare const unsafeUnwrap: <A>(x: IOEither<unknown, A>) => A; /** * Unwrap the value from within an `IOEither`, throwing the inner value of * `Right` if `Right`. * * @example * import { unsafeUnwrapLeft } from 'fp-ts-std/IOEither' * import * as IOE from 'fp-ts/IOEither' * * assert.strictEqual(unsafeUnwrapLeft(IOE.left(5)), 5) * * @category 3 Functions * @since 0.15.0 */ export declare const unsafeUnwrapLeft: <E>(x: IOEither<E, unknown>) => E; /** * Unwrap the value from within an `IOEither`, throwing the inner value of * `Left` via `Show` if `Left`. * * @example * import { unsafeExpect } from 'fp-ts-std/IOEither' * import * as IOE from 'fp-ts/IOEither' * import * as Str from 'fp-ts/string' * * assert.throws( * () => unsafeExpect(Str.Show)(IOE.left('foo')), * Error('Unwrapped `Left`', { cause: '"foo"' }), * ) * * @category 3 Functions * @since 0.16.0 */ export declare const unsafeExpect: <E>(S: Show<E>) => <A>(x: IOEither<E, A>) => A; /** * Unwrap the value from within an `IOEither`, throwing the inner value of * `Right` via `Show` if `Right`. * * @example * import { unsafeExpectLeft } from 'fp-ts-std/IOEither' * import * as IOE from 'fp-ts/IOEither' * import * as Str from 'fp-ts/string' * * assert.throws( * () => unsafeExpectLeft(Str.Show)(IOE.right('foo')), * Error('Unwrapped `Right`', { cause: '"foo"' }), * ) * * @category 3 Functions * @since 0.16.0 */ export declare const unsafeExpectLeft: <A>(S: Show<A>) => <E>(x: IOEither<E, A>) => E; /** * Sequence an array of fallible effects, ignoring the results. * * @category 2 Typeclass Methods * @since 0.15.0 */ export declare const sequenceArray_: <E, A>(xs: ReadonlyArray<IOEither<E, A>>) => IOEither<E, void>; /** * Map to and sequence an array of fallible effects, ignoring the results. * * @category 2 Typeclass Methods * @since 0.15.0 */ export declare const traverseArray_: <E, A, B>(f: (x: A) => IOEither<E, B>) => (xs: ReadonlyArray<A>) => IOEither<E, void>; /** * Convenient alias for `IOE.of(undefined)`. * * @example * import { flow, pipe, constant } from 'fp-ts/function' * import * as Fn from 'fp-ts-std/Function' * import * as O from 'fp-ts/Option' * import Option = O.Option * import * as IOE from 'fp-ts/IOEither' * import IOEither = IOE.IOEither * import { pass } from 'fp-ts-std/IOEither' * import { log } from 'fp-ts/Console' * * const mcount: Option<number> = O.some(123) * const tryLog: <A>(x: A) => IOEither<void, void> = flow(log, IOE.fromIO) * * const logCount: IOEither<void, void> = pipe( * mcount, * O.match( * constant(pass), * tryLog, * ), * ) * * @category 2 Typeclass Methods * @since 0.17.0 */ export declare const pass: IOEither<never, void>; //# sourceMappingURL=IOEither.d.ts.map