fp-ts-std
Version:
The missing pseudo-standard library for fp-ts.
133 lines • 3.96 kB
TypeScript
/**
* Utility functions to accommodate `fp-ts/TaskEither`.
*
* @since 0.12.0
*/
import type { Show } from "fp-ts/Show";
import type { TaskEither } from "fp-ts/TaskEither";
/**
* Unwrap the promise from within a `TaskEither`, rejecting with the inner
* value of `Left` if `Left`.
*
* @example
* import { unsafeUnwrap } from 'fp-ts-std/TaskEither'
* import * as TE from 'fp-ts/TaskEither'
*
* unsafeUnwrap(TE.right(5)).then((x) => {
* assert.strictEqual(x, 5)
* })
*
* @category 3 Functions
* @since 0.12.0
*/
export declare const unsafeUnwrap: <A>(x: TaskEither<unknown, A>) => Promise<A>;
/**
* Unwrap the promise from within a `TaskEither`, throwing the inner value of
* `Right` if `Right`.
*
* @example
* import { unsafeUnwrapLeft } from 'fp-ts-std/TaskEither'
* import * as TE from 'fp-ts/TaskEither'
*
* unsafeUnwrapLeft(TE.left(5)).then((x) => {
* assert.strictEqual(x, 5)
* })
*
* @category 3 Functions
* @since 0.12.0
*/
export declare const unsafeUnwrapLeft: <E>(x: TaskEither<E, unknown>) => Promise<E>;
/**
* Unwrap the promise from within a `TaskEither`, rejecting with the inner
* value of `Left` via `Show` if `Left`.
*
* @example
* import { unsafeExpect } from 'fp-ts-std/TaskEither'
* import * as TE from 'fp-ts/TaskEither'
* import * as Str from 'fp-ts/string'
*
* assert.rejects(
* unsafeExpect(Str.Show)(TE.left('foo')),
* Error('Unwrapped `Left`', { cause: 'foo' }),
* )
*
* @category 3 Functions
* @since 0.16.0
*/
export declare const unsafeExpect: <E>(S: Show<E>) => <A>(x: TaskEither<E, A>) => Promise<A>;
/**
* Unwrap the promise from within a `TaskEither`, rejecting with the inner
* value of `Right` via `Show` if `Right`.
*
* @example
* import { unsafeExpectLeft } from 'fp-ts-std/TaskEither'
* import * as TE from 'fp-ts/TaskEither'
* import * as Str from 'fp-ts/string'
*
* assert.rejects(
* unsafeExpectLeft(Str.Show)(TE.right('foo')),
* Error('Unwrapped `Right`', { cause: '"foo"' }),
* )
*
* @category 3 Functions
* @since 0.16.0
*/
export declare const unsafeExpectLeft: <A>(S: Show<A>) => <E>(x: TaskEither<E, A>) => Promise<E>;
/**
* Sequence an array of fallible tasks, ignoring the results.
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare const sequenceArray_: <E, A>(xs: ReadonlyArray<TaskEither<E, A>>) => TaskEither<E, void>;
/**
* Sequentially sequence an array of fallible tasks, ignoring the results.
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare const sequenceSeqArray_: <E, A>(xs: ReadonlyArray<TaskEither<E, A>>) => TaskEither<E, void>;
/**
* Map to and sequence an array of fallible tasks, ignoring the results.
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare const traverseArray_: <E, A, B>(f: (x: A) => TaskEither<E, B>) => (xs: ReadonlyArray<A>) => TaskEither<E, void>;
/**
* Sequentially map to and sequence an array of fallible tasks, ignoring the
* results.
*
* @category 2 Typeclass Methods
* @since 0.15.0
*/
export declare const traverseSeqArray_: <E, A, B>(f: (x: A) => TaskEither<E, B>) => (xs: ReadonlyArray<A>) => TaskEither<E, void>;
/**
* Convenient alias for `TE.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 TE from 'fp-ts/TaskEither'
* import TaskEither = TE.TaskEither
* import { pass } from 'fp-ts-std/TaskEither'
* import { log } from 'fp-ts/Console'
*
* const mcount: Option<number> = O.some(123)
* const tryAsyncLog: <A>(x: A) => TaskEither<void, void> = flow(log, TE.fromIO)
*
* const logCount: TaskEither<void, void> = pipe(
* mcount,
* O.match(
* constant(pass),
* tryAsyncLog,
* ),
* )
*
* @category 2 Typeclass Methods
* @since 0.17.0
*/
export declare const pass: TaskEither<never, void>;
//# sourceMappingURL=TaskEither.d.ts.map