|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126 |
- /**
- * ```ts
- * interface TaskEither<E, A> extends Task<Either<E, A>> {}
- * ```
- *
- * `TaskEither<E, A>` represents an asynchronous computation that either yields a value of type `A` or fails yielding an
- * error of type `E`. If you want to represent an asynchronous computation that never fails, please see `Task`.
- *
- * @since 2.0.0
- */
- import { Alt2, Alt2C } from './Alt'
- import { Applicative2, Applicative2C } from './Applicative'
- import { Apply1, Apply2 } from './Apply'
- import { Bifunctor2 } from './Bifunctor'
- import { Chain2 } from './Chain'
- import { Compactable2C } from './Compactable'
- import * as E from './Either'
- import { Filterable2C } from './Filterable'
- import { FromEither2 } from './FromEither'
- import { FromIO2 } from './FromIO'
- import { FromTask2 } from './FromTask'
- import { Lazy } from './function'
- import { Functor2 } from './Functor'
- import { IO } from './IO'
- import { IOEither } from './IOEither'
- import { Monad2, Monad2C } from './Monad'
- import { MonadIO2 } from './MonadIO'
- import { MonadTask2, MonadTask2C } from './MonadTask'
- import { MonadThrow2, MonadThrow2C } from './MonadThrow'
- import { Monoid } from './Monoid'
- import { Option } from './Option'
- import { Pointed2 } from './Pointed'
- import { Predicate } from './Predicate'
- import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
- import { Refinement } from './Refinement'
- import { Semigroup } from './Semigroup'
- import * as T from './Task'
- import { TaskOption } from './TaskOption'
- import Either = E.Either
- import Task = T.Task
- /**
- * @category model
- * @since 2.0.0
- */
- export interface TaskEither<E, A> extends Task<Either<E, A>> {}
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const left: <E = never, A = never>(e: E) => TaskEither<E, A>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const right: <E = never, A = never>(a: A) => TaskEither<E, A>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const rightTask: <E = never, A = never>(ma: Task<A>) => TaskEither<E, A>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const leftTask: <E = never, A = never>(me: Task<E>) => TaskEither<E, A>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const rightIO: <E = never, A = never>(ma: IO<A>) => TaskEither<E, A>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const leftIO: <E = never, A = never>(me: IO<E>) => TaskEither<E, A>
- /**
- * @category conversions
- * @since 2.7.0
- */
- export declare const fromIO: <A, E = never>(fa: IO<A>) => TaskEither<E, A>
- /**
- * @category conversions
- * @since 2.7.0
- */
- export declare const fromTask: <A, E = never>(fa: Task<A>) => TaskEither<E, A>
- /**
- * @category conversions
- * @since 2.0.0
- */
- export declare const fromEither: <E, A>(fa: Either<E, A>) => TaskEither<E, A>
- /**
- * @category conversions
- * @since 2.0.0
- */
- export declare const fromIOEither: <E, A>(fa: IOEither<E, A>) => TaskEither<E, A>
- /**
- * @category conversions
- * @since 2.11.0
- */
- export declare const fromTaskOption: <E>(onNone: Lazy<E>) => <A>(fa: TaskOption<A>) => TaskEither<E, A>
- /**
- * @category pattern matching
- * @since 2.10.0
- */
- export declare const match: <E, B, A>(onLeft: (e: E) => B, onRight: (a: A) => B) => (ma: TaskEither<E, A>) => Task<B>
- /**
- * Less strict version of [`match`](#match).
- *
- * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
- *
- * @category pattern matching
- * @since 2.10.0
- */
- export declare const matchW: <E, B, A, C>(
- onLeft: (e: E) => B,
- onRight: (a: A) => C
- ) => (ma: TaskEither<E, A>) => Task<B | C>
- /**
- * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`Task`).
- *
- * @category pattern matching
- * @since 2.10.0
- */
- export declare const matchE: <E, A, B>(
- onLeft: (e: E) => Task<B>,
- onRight: (a: A) => Task<B>
- ) => (ma: TaskEither<E, A>) => Task<B>
- /**
- * Alias of [`matchE`](#matche).
- *
- * @category pattern matching
- * @since 2.0.0
- */
- export declare const fold: <E, A, B>(
- onLeft: (e: E) => T.Task<B>,
- onRight: (a: A) => T.Task<B>
- ) => (ma: TaskEither<E, A>) => T.Task<B>
- /**
- * Less strict version of [`matchE`](#matche).
- *
- * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
- *
- * @category pattern matching
- * @since 2.10.0
- */
- export declare const matchEW: <E, B, A, C>(
- onLeft: (e: E) => Task<B>,
- onRight: (a: A) => Task<C>
- ) => (ma: TaskEither<E, A>) => Task<B | C>
- /**
- * Alias of [`matchEW`](#matchew).
- *
- * @category pattern matching
- * @since 2.10.0
- */
- export declare const foldW: <E, B, A, C>(
- onLeft: (e: E) => T.Task<B>,
- onRight: (a: A) => T.Task<C>
- ) => (ma: TaskEither<E, A>) => T.Task<B | C>
- /**
- * @category error handling
- * @since 2.0.0
- */
- export declare const getOrElse: <E, A>(onLeft: (e: E) => Task<A>) => (ma: TaskEither<E, A>) => Task<A>
- /**
- * Less strict version of [`getOrElse`](#getorelse).
- *
- * The `W` suffix (short for **W**idening) means that the handler return type will be merged.
- *
- * @category error handling
- * @since 2.6.0
- */
- export declare const getOrElseW: <E, B>(onLeft: (e: E) => Task<B>) => <A>(ma: TaskEither<E, A>) => Task<A | B>
- /**
- * Transforms a `Promise` that may reject to a `Promise` that never rejects and returns an `Either` instead.
- *
- * See also [`tryCatchK`](#trycatchk).
- *
- * @example
- * import { left, right } from 'fp-ts/Either'
- * import { tryCatch } from 'fp-ts/TaskEither'
- *
- * tryCatch(() => Promise.resolve(1), String)().then(result => {
- * assert.deepStrictEqual(result, right(1))
- * })
- * tryCatch(() => Promise.reject('error'), String)().then(result => {
- * assert.deepStrictEqual(result, left('error'))
- * })
- *
- * @category interop
- * @since 2.0.0
- */
- export declare const tryCatch: <E, A>(f: Lazy<Promise<A>>, onRejected: (reason: unknown) => E) => TaskEither<E, A>
- /**
- * Converts a function returning a `Promise` to one returning a `TaskEither`.
- *
- * @category interop
- * @since 2.5.0
- */
- export declare const tryCatchK: <E, A extends readonly unknown[], B>(
- f: (...a: A) => Promise<B>,
- onRejected: (reason: unknown) => E
- ) => (...a: A) => TaskEither<E, B>
- /**
- * @category conversions
- * @since 2.10.0
- */
- export declare const toUnion: <E, A>(fa: TaskEither<E, A>) => Task<E | A>
- /**
- * @category conversions
- * @since 2.12.0
- */
- export declare const fromNullable: <E>(e: E) => <A>(a: A) => TaskEither<E, NonNullable<A>>
- /**
- * @category lifting
- * @since 2.12.0
- */
- export declare const fromNullableK: <E>(
- e: E
- ) => <A extends ReadonlyArray<unknown>, B>(
- f: (...a: A) => B | null | undefined
- ) => (...a: A) => TaskEither<E, NonNullable<B>>
- /**
- * @category sequencing
- * @since 2.12.0
- */
- export declare const chainNullableK: <E>(
- e: E
- ) => <A, B>(f: (a: A) => B | null | undefined) => (ma: TaskEither<E, A>) => TaskEither<E, NonNullable<B>>
- /**
- * Returns `ma` if is a `Right` or the value returned by `onLeft` otherwise.
- *
- * See also [alt](#alt).
- *
- * @example
- * import * as E from 'fp-ts/Either'
- * import { pipe } from 'fp-ts/function'
- * import * as TE from 'fp-ts/TaskEither'
- *
- * async function test() {
- * const errorHandler = TE.orElse((error: string) => TE.right(`recovering from ${error}...`))
- * assert.deepStrictEqual(await pipe(TE.right('ok'), errorHandler)(), E.right('ok'))
- * assert.deepStrictEqual(await pipe(TE.left('ko'), errorHandler)(), E.right('recovering from ko...'))
- * }
- *
- * test()
- *
- * @category error handling
- * @since 2.0.0
- */
- export declare const orElse: <E1, A, E2>(
- onLeft: (e: E1) => TaskEither<E2, A>
- ) => (ma: TaskEither<E1, A>) => TaskEither<E2, A>
- /**
- * Less strict version of [`orElse`](#orelse).
- *
- * The `W` suffix (short for **W**idening) means that the return types will be merged.
- *
- * @category error handling
- * @since 2.10.0
- */
- export declare const orElseW: <E1, E2, B>(
- onLeft: (e: E1) => TaskEither<E2, B>
- ) => <A>(ma: TaskEither<E1, A>) => TaskEither<E2, A | B>
- /**
- * @category error handling
- * @since 2.11.0
- */
- export declare const orElseFirst: <E, B>(
- onLeft: (e: E) => TaskEither<E, B>
- ) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category error handling
- * @since 2.11.0
- */
- export declare const orElseFirstW: <E1, E2, B>(
- onLeft: (e: E1) => TaskEither<E2, B>
- ) => <A>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
- /**
- * @category error handling
- * @since 2.12.0
- */
- export declare const orElseFirstIOK: <E, B>(onLeft: (e: E) => IO<B>) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * @category error handling
- * @since 2.12.0
- */
- export declare const orElseFirstTaskK: <E, B>(
- onLeft: (e: E) => Task<B>
- ) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * @category error handling
- * @since 2.11.0
- */
- export declare const orLeft: <E1, E2>(onLeft: (e: E1) => Task<E2>) => <A>(fa: TaskEither<E1, A>) => TaskEither<E2, A>
- /**
- * @since 2.0.0
- */
- export declare const swap: <E, A>(ma: TaskEither<E, A>) => TaskEither<A, E>
- /**
- * @category lifting
- * @since 2.11.0
- */
- export declare const fromTaskOptionK: <E>(
- onNone: Lazy<E>
- ) => <A extends readonly unknown[], B>(f: (...a: A) => TaskOption<B>) => (...a: A) => TaskEither<E, B>
- /**
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.12.3
- */
- export declare const chainTaskOptionKW: <E2>(
- onNone: Lazy<E2>
- ) => <A, B>(f: (a: A) => TaskOption<B>) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
- /**
- * @category sequencing
- * @since 2.11.0
- */
- export declare const chainTaskOptionK: <E>(
- onNone: Lazy<E>
- ) => <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * @category lifting
- * @since 2.4.0
- */
- export declare const fromIOEitherK: <E, A extends readonly unknown[], B>(
- f: (...a: A) => IOEither<E, B>
- ) => (...a: A) => TaskEither<E, B>
- /**
- * Less strict version of [`chainIOEitherK`](#chainioeitherk).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.6.1
- */
- export declare const chainIOEitherKW: <E2, A, B>(
- f: (a: A) => IOEither<E2, B>
- ) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B>
- /**
- * @category sequencing
- * @since 2.4.0
- */
- export declare const chainIOEitherK: <E, A, B>(
- f: (a: A) => IOEither<E, B>
- ) => (ma: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
- * use the type constructor `F` to represent some computational context.
- *
- * @category mapping
- * @since 2.0.0
- */
- export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * Map a pair of functions over the two type arguments of the bifunctor.
- *
- * @category mapping
- * @since 2.0.0
- */
- export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: TaskEither<E, A>) => TaskEither<G, B>
- /**
- * Map a function over the first type argument of a bifunctor.
- *
- * @category error handling
- * @since 2.0.0
- */
- export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: TaskEither<E, A>) => TaskEither<G, A>
- /**
- * @since 2.0.0
- */
- export declare const ap: <E, A>(fa: TaskEither<E, A>) => <B>(fab: TaskEither<E, (a: A) => B>) => TaskEither<E, B>
- /**
- * Less strict version of [`ap`](#ap).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @since 2.8.0
- */
- export declare const apW: <E2, A>(
- fa: TaskEither<E2, A>
- ) => <E1, B>(fab: TaskEither<E1, (a: A) => B>) => TaskEither<E1 | E2, B>
- /**
- * Composes computations in sequence, using the return value of one computation to determine the next computation.
- *
- * @category sequencing
- * @since 2.0.0
- */
- export declare const chain: <E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * Less strict version of [`chain`](#chain).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.6.0
- */
- export declare const chainW: <E2, A, B>(
- f: (a: A) => TaskEither<E2, B>
- ) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B>
- /**
- * Less strict version of [`flatten`](#flatten).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.11.0
- */
- export declare const flattenW: <E1, E2, A>(mma: TaskEither<E1, TaskEither<E2, A>>) => TaskEither<E1 | E2, A>
- /**
- * @category sequencing
- * @since 2.0.0
- */
- export declare const flatten: <E, A>(mma: TaskEither<E, TaskEither<E, A>>) => TaskEither<E, A>
- /**
- * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
- * types of kind `* -> *`.
- *
- * In case of `TaskEither` returns `fa` if is a `Right` or the value returned by `that` otherwise.
- *
- * See also [orElse](#orelse).
- *
- * @example
- * import * as E from 'fp-ts/Either'
- * import { pipe } from 'fp-ts/function'
- * import * as TE from 'fp-ts/TaskEither'
- *
- * async function test() {
- * assert.deepStrictEqual(
- * await pipe(
- * TE.right(1),
- * TE.alt(() => TE.right(2))
- * )(),
- * E.right(1)
- * )
- * assert.deepStrictEqual(
- * await pipe(
- * TE.left('a'),
- * TE.alt(() => TE.right(2))
- * )(),
- * E.right(2)
- * )
- * assert.deepStrictEqual(
- * await pipe(
- * TE.left('a'),
- * TE.alt(() => TE.left('b'))
- * )(),
- * E.left('b')
- * )
- * }
- *
- * test()
- *
- * @category error handling
- * @since 2.0.0
- */
- export declare const alt: <E, A>(that: Lazy<TaskEither<E, A>>) => (fa: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * Less strict version of [`alt`](#alt).
- *
- * The `W` suffix (short for **W**idening) means that the error and the return types will be merged.
- *
- * @category error handling
- * @since 2.9.0
- */
- export declare const altW: <E2, B>(
- that: Lazy<TaskEither<E2, B>>
- ) => <E1, A>(fa: TaskEither<E1, A>) => TaskEither<E2, A | B>
- /**
- * @category constructors
- * @since 2.0.0
- */
- export declare const of: <E = never, A = never>(a: A) => TaskEither<E, A>
- /**
- * @since 2.7.0
- */
- export declare const throwError: MonadThrow2<URI>['throwError']
- /**
- * @category type lambdas
- * @since 2.0.0
- */
- export declare const URI = 'TaskEither'
- /**
- * @category type lambdas
- * @since 2.0.0
- */
- export declare type URI = typeof URI
- declare module './HKT' {
- interface URItoKind2<E, A> {
- readonly [URI]: TaskEither<E, A>
- }
- }
- /**
- * The default [`ApplicativePar`](#applicativepar) instance returns the first error, if you want to
- * get all errors you need to provide a way to concatenate them via a `Semigroup`.
- *
- * @example
- * import * as E from 'fp-ts/Either'
- * import { pipe } from 'fp-ts/function'
- * import * as RA from 'fp-ts/ReadonlyArray'
- * import * as S from 'fp-ts/Semigroup'
- * import * as string from 'fp-ts/string'
- * import * as T from 'fp-ts/Task'
- * import * as TE from 'fp-ts/TaskEither'
- *
- * interface User {
- * readonly id: string
- * readonly name: string
- * }
- *
- * const remoteDatabase: ReadonlyArray<User> = [
- * { id: 'id1', name: 'John' },
- * { id: 'id2', name: 'Mary' },
- * { id: 'id3', name: 'Joey' }
- * ]
- *
- * const fetchUser = (id: string): TE.TaskEither<string, User> =>
- * pipe(
- * remoteDatabase,
- * RA.findFirst((user) => user.id === id),
- * TE.fromOption(() => `${id} not found`)
- * )
- *
- * async function test() {
- * assert.deepStrictEqual(
- * await pipe(['id4', 'id5'], RA.traverse(TE.ApplicativePar)(fetchUser))(),
- * E.left('id4 not found') // <= first error
- * )
- *
- * const Applicative = TE.getApplicativeTaskValidation(
- * T.ApplyPar,
- * pipe(string.Semigroup, S.intercalate(', '))
- * )
- *
- * assert.deepStrictEqual(
- * await pipe(['id4', 'id5'], RA.traverse(Applicative)(fetchUser))(),
- * E.left('id4 not found, id5 not found') // <= all errors
- * )
- * }
- *
- * test()
- *
- * @category error handling
- * @since 2.7.0
- */
- export declare function getApplicativeTaskValidation<E>(A: Apply1<T.URI>, S: Semigroup<E>): Applicative2C<URI, E>
- /**
- * The default [`Alt`](#alt) instance returns the last error, if you want to
- * get all errors you need to provide a way to concatenate them via a `Semigroup`.
- *
- * See [`getAltValidation`](./Either.ts.html#getaltvalidation).
- *
- * @category error handling
- * @since 2.7.0
- */
- export declare function getAltTaskValidation<E>(S: Semigroup<E>): Alt2C<URI, E>
- /**
- * @category filtering
- * @since 2.10.0
- */
- export declare const getCompactable: <E>(M: Monoid<E>) => Compactable2C<'TaskEither', E>
- /**
- * @category filtering
- * @since 2.1.0
- */
- export declare function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E>
- /**
- * @category instances
- * @since 2.7.0
- */
- export declare const Functor: Functor2<URI>
- /**
- * @category mapping
- * @since 2.10.0
- */
- export declare const flap: <A>(a: A) => <E, B>(fab: TaskEither<E, (a: A) => B>) => TaskEither<E, B>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const Pointed: Pointed2<URI>
- /**
- * Runs computations in parallel.
- *
- * @category instances
- * @since 2.10.0
- */
- export declare const ApplyPar: Apply2<URI>
- /**
- * Combine two effectful actions, keeping only the result of the first.
- *
- * @since 2.0.0
- */
- export declare const apFirst: <E, B>(second: TaskEither<E, B>) => <A>(first: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * Less strict version of [`apFirst`](#apfirst).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @since 2.12.0
- */
- export declare const apFirstW: <E2, B>(
- second: TaskEither<E2, B>
- ) => <E1, A>(first: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
- /**
- * Combine two effectful actions, keeping only the result of the second.
- *
- * @since 2.0.0
- */
- export declare const apSecond: <E, B>(second: TaskEither<E, B>) => <A>(first: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * Less strict version of [`apSecond`](#apsecond).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @since 2.12.0
- */
- export declare const apSecondW: <E2, B>(
- second: TaskEither<E2, B>
- ) => <E1, A>(first: TaskEither<E1, A>) => TaskEither<E1 | E2, B>
- /**
- * Runs computations in parallel.
- *
- * @category instances
- * @since 2.7.0
- */
- export declare const ApplicativePar: Applicative2<URI>
- /**
- * Runs computations sequentially.
- *
- * @category instances
- * @since 2.10.0
- */
- export declare const ApplySeq: Apply2<URI>
- /**
- * Runs computations sequentially.
- *
- * @category instances
- * @since 2.7.0
- */
- export declare const ApplicativeSeq: Applicative2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const Chain: Chain2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const Monad: Monad2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const MonadIO: MonadIO2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const MonadTask: MonadTask2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const MonadThrow: MonadThrow2<URI>
- /**
- * Composes computations in sequence, using the return value of one computation to determine the next computation and
- * keeping only the result of the first.
- *
- * @category sequencing
- * @since 2.0.0
- */
- export declare const chainFirst: <E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * Less strict version of [`chainFirst`](#chainfirst).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.8.0
- */
- export declare const chainFirstW: <E2, A, B>(
- f: (a: A) => TaskEither<E2, B>
- ) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
- /**
- * @category instances
- * @since 2.7.0
- */
- export declare const Bifunctor: Bifunctor2<URI>
- /**
- * @category instances
- * @since 2.7.0
- */
- export declare const Alt: Alt2<URI>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const FromEither: FromEither2<URI>
- /**
- * @category conversions
- * @since 2.0.0
- */
- export declare const fromOption: <E>(onNone: Lazy<E>) => <A>(fa: Option<A>) => TaskEither<E, A>
- /**
- * @category lifting
- * @since 2.10.0
- */
- export declare const fromOptionK: <E>(
- onNone: Lazy<E>
- ) => <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => Option<B>) => (...a: A) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.10.0
- */
- export declare const chainOptionK: <E>(
- onNone: Lazy<E>
- ) => <A, B>(f: (a: A) => Option<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.4.0
- */
- export declare const chainEitherK: <E, A, B>(f: (a: A) => E.Either<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * Less strict version of [`chainEitherK`](#chaineitherk).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.6.1
- */
- export declare const chainEitherKW: <E2, A, B>(
- f: (a: A) => Either<E2, B>
- ) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B>
- /**
- * @category sequencing
- * @since 2.12.0
- */
- export declare const chainFirstEitherK: <A, E, B>(
- f: (a: A) => E.Either<E, B>
- ) => (ma: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * Less strict version of [`chainFirstEitherK`](#chainfirsteitherk).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category sequencing
- * @since 2.12.0
- */
- export declare const chainFirstEitherKW: <A, E2, B>(
- f: (a: A) => E.Either<E2, B>
- ) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
- /**
- * @category lifting
- * @since 2.0.0
- */
- export declare const fromPredicate: {
- <E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => TaskEither<E, B>
- <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(b: B) => TaskEither<E, B>
- <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => TaskEither<E, A>
- }
- /**
- * @category filtering
- * @since 2.0.0
- */
- export declare const filterOrElse: {
- <E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (ma: TaskEither<E, A>) => TaskEither<E, B>
- <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(mb: TaskEither<E, B>) => TaskEither<E, B>
- <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (ma: TaskEither<E, A>) => TaskEither<E, A>
- }
- /**
- * Less strict version of [`filterOrElse`](#filterorelse).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category filtering
- * @since 2.9.0
- */
- export declare const filterOrElseW: {
- <A, B extends A, E2>(refinement: Refinement<A, B>, onFalse: (a: A) => E2): <E1>(
- ma: TaskEither<E1, A>
- ) => TaskEither<E1 | E2, B>
- <A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1, B extends A>(
- mb: TaskEither<E1, B>
- ) => TaskEither<E1 | E2, B>
- <A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
- }
- /**
- * @category lifting
- * @since 2.4.0
- */
- export declare const fromEitherK: <E, A extends ReadonlyArray<unknown>, B>(
- f: (...a: A) => E.Either<E, B>
- ) => (...a: A) => TaskEither<E, B>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const FromIO: FromIO2<URI>
- /**
- * @category lifting
- * @since 2.10.0
- */
- export declare const fromIOK: <A extends ReadonlyArray<unknown>, B>(
- f: (...a: A) => IO<B>
- ) => <E = never>(...a: A) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.10.0
- */
- export declare const chainIOK: <A, B>(f: (a: A) => IO<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.10.0
- */
- export declare const chainFirstIOK: <A, B>(f: (a: A) => IO<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * @category instances
- * @since 2.10.0
- */
- export declare const FromTask: FromTask2<URI>
- /**
- * @category lifting
- * @since 2.10.0
- */
- export declare const fromTaskK: <A extends ReadonlyArray<unknown>, B>(
- f: (...a: A) => T.Task<B>
- ) => <E = never>(...a: A) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.10.0
- */
- export declare const chainTaskK: <A, B>(f: (a: A) => T.Task<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, B>
- /**
- * @category sequencing
- * @since 2.10.0
- */
- export declare const chainFirstTaskK: <A, B>(f: (a: A) => T.Task<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, A>
- /**
- * Convert a node style callback function to one returning a `TaskEither`
- *
- * **Note**. If the function `f` admits multiple overloadings, `taskify` will pick last one. If you want a different
- * behaviour, add an explicit type annotation
- *
- * ```ts
- * // readFile admits multiple overloadings
- *
- * // const readFile: (a: string) => TaskEither<NodeJS.ErrnoException, Buffer>
- * const readFile = taskify(fs.readFile)
- *
- * const readFile2: (filename: string, encoding: string) => TaskEither<NodeJS.ErrnoException, Buffer> = taskify(
- * fs.readFile
- * )
- * ```
- *
- * @example
- * import { taskify } from 'fp-ts/TaskEither'
- * import * as fs from 'fs'
- *
- * // const stat: (a: string | Buffer) => TaskEither<NodeJS.ErrnoException, fs.Stats>
- * const stat = taskify(fs.stat)
- * assert.strictEqual(stat.length, 0)
- *
- * @category interop
- * @since 2.0.0
- */
- export declare function taskify<L, R>(f: (cb: (e: L | null | undefined, r?: R) => void) => void): () => TaskEither<L, R>
- export declare function taskify<A, L, R>(
- f: (a: A, cb: (e: L | null | undefined, r?: R) => void) => void
- ): (a: A) => TaskEither<L, R>
- export declare function taskify<A, B, L, R>(
- f: (a: A, b: B, cb: (e: L | null | undefined, r?: R) => void) => void
- ): (a: A, b: B) => TaskEither<L, R>
- export declare function taskify<A, B, C, L, R>(
- f: (a: A, b: B, c: C, cb: (e: L | null | undefined, r?: R) => void) => void
- ): (a: A, b: B, c: C) => TaskEither<L, R>
- export declare function taskify<A, B, C, D, L, R>(
- f: (a: A, b: B, c: C, d: D, cb: (e: L | null | undefined, r?: R) => void) => void
- ): (a: A, b: B, c: C, d: D) => TaskEither<L, R>
- export declare function taskify<A, B, C, D, E, L, R>(
- f: (a: A, b: B, c: C, d: D, e: E, cb: (e: L | null | undefined, r?: R) => void) => void
- ): (a: A, b: B, c: C, d: D, e: E) => TaskEither<L, R>
- /**
- * Make sure that a resource is cleaned up in the event of an exception (\*). The release action is called regardless of
- * whether the body action throws (\*) or returns.
- *
- * (\*) i.e. returns a `Left`
- *
- * @since 2.0.0
- */
- export declare const bracket: <E, A, B>(
- acquire: TaskEither<E, A>,
- use: (a: A) => TaskEither<E, B>,
- release: (a: A, e: E.Either<E, B>) => TaskEither<E, void>
- ) => TaskEither<E, B>
- /**
- * Less strict version of [`bracket`](#bracket).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @since 2.12.0
- */
- export declare const bracketW: <E1, A, E2, B, E3>(
- acquire: TaskEither<E1, A>,
- use: (a: A) => TaskEither<E2, B>,
- release: (a: A, e: E.Either<E2, B>) => TaskEither<E3, void>
- ) => TaskEither<E1 | E2 | E3, B>
- /**
- * @category do notation
- * @since 2.9.0
- */
- export declare const Do: TaskEither<never, {}>
- /**
- * @category do notation
- * @since 2.8.0
- */
- export declare const bindTo: <N extends string>(
- name: N
- ) => <E, A>(fa: TaskEither<E, A>) => TaskEither<E, { readonly [K in N]: A }>
- declare const let_: <N extends string, A, B>(
- name: Exclude<N, keyof A>,
- f: (a: A) => B
- ) => <E>(fa: TaskEither<E, A>) => TaskEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
- export {
- /**
- * @category do notation
- * @since 2.13.0
- */
- let_ as let
- }
- /**
- * @category do notation
- * @since 2.8.0
- */
- export declare const bind: <N extends string, A, E, B>(
- name: Exclude<N, keyof A>,
- f: (a: A) => TaskEither<E, B>
- ) => (ma: TaskEither<E, A>) => TaskEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
- /**
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category do notation
- * @since 2.8.0
- */
- export declare const bindW: <N extends string, A, E2, B>(
- name: Exclude<N, keyof A>,
- f: (a: A) => TaskEither<E2, B>
- ) => <E1>(fa: TaskEither<E1, A>) => TaskEither<
- E1 | E2,
- {
- readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
- }
- >
- /**
- * @category do notation
- * @since 2.8.0
- */
- export declare const apS: <N extends string, A, E, B>(
- name: Exclude<N, keyof A>,
- fb: TaskEither<E, B>
- ) => (fa: TaskEither<E, A>) => TaskEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
- /**
- * Less strict version of [`apS`](#aps).
- *
- * The `W` suffix (short for **W**idening) means that the error types will be merged.
- *
- * @category do notation
- * @since 2.8.0
- */
- export declare const apSW: <A, N extends string, E2, B>(
- name: Exclude<N, keyof A>,
- fb: TaskEither<E2, B>
- ) => <E1>(fa: TaskEither<E1, A>) => TaskEither<
- E1 | E2,
- {
- readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
- }
- >
- /**
- * @since 2.11.0
- */
- export declare const ApT: TaskEither<never, readonly []>
- /**
- * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)`.
- *
- * @category traversing
- * @since 2.11.0
- */
- export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, E, B>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: ReadonlyNonEmptyArray<A>) => TaskEither<E, ReadonlyNonEmptyArray<B>>
- /**
- * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativePar)`.
- *
- * @category traversing
- * @since 2.11.0
- */
- export declare const traverseReadonlyArrayWithIndex: <A, E, B>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: readonly A[]) => TaskEither<E, readonly B[]>
- /**
- * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
- *
- * @category traversing
- * @since 2.11.0
- */
- export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: <A, E, B>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: ReadonlyNonEmptyArray<A>) => TaskEither<E, ReadonlyNonEmptyArray<B>>
- /**
- * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
- *
- * @category traversing
- * @since 2.11.0
- */
- export declare const traverseReadonlyArrayWithIndexSeq: <A, E, B>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: readonly A[]) => TaskEither<E, readonly B[]>
- /**
- * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const traverseArrayWithIndex: <A, B, E>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: ReadonlyArray<A>) => TaskEither<E, ReadonlyArray<B>>
- /**
- * Equivalent to `ReadonlyArray#traverse(Applicative)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const traverseArray: <A, B, E>(
- f: (a: A) => TaskEither<E, B>
- ) => (as: readonly A[]) => TaskEither<E, readonly B[]>
- /**
- * Equivalent to `ReadonlyArray#sequence(Applicative)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const sequenceArray: <A, E>(arr: ReadonlyArray<TaskEither<E, A>>) => TaskEither<E, ReadonlyArray<A>>
- /**
- * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const traverseSeqArrayWithIndex: <A, B, E>(
- f: (index: number, a: A) => TaskEither<E, B>
- ) => (as: ReadonlyArray<A>) => TaskEither<E, ReadonlyArray<B>>
- /**
- * Equivalent to `ReadonlyArray#traverse(ApplicativeSeq)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const traverseSeqArray: <A, B, E>(
- f: (a: A) => TaskEither<E, B>
- ) => (as: readonly A[]) => TaskEither<E, readonly B[]>
- /**
- * Equivalent to `ReadonlyArray#sequence(ApplicativeSeq)`.
- *
- * @category traversing
- * @since 2.9.0
- */
- export declare const sequenceSeqArray: <A, E>(arr: ReadonlyArray<TaskEither<E, A>>) => TaskEither<E, ReadonlyArray<A>>
- /**
- * This instance is deprecated, use small, specific instances instead.
- * For example if a function needs a `Functor` instance, pass `TE.Functor` instead of `TE.taskEither`
- * (where `TE` is from `import TE from 'fp-ts/TaskEither'`)
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare const taskEither: Monad2<URI> & Bifunctor2<URI> & Alt2<URI> & MonadTask2<URI> & MonadThrow2<URI>
- /**
- * This instance is deprecated, use small, specific instances instead.
- * For example if a function needs a `Functor` instance, pass `TE.Functor` instead of `TE.taskEitherSeq`
- * (where `TE` is from `import TE from 'fp-ts/TaskEither'`)
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare const taskEitherSeq: typeof taskEither
- /**
- * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare const getApplySemigroup: <E, A>(S: Semigroup<A>) => Semigroup<TaskEither<E, A>>
- /**
- * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead.
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare const getApplyMonoid: <E, A>(M: Monoid<A>) => Monoid<TaskEither<E, A>>
- /**
- * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare const getSemigroup: <E, A>(S: Semigroup<A>) => Semigroup<TaskEither<E, A>>
- /**
- * Use [`getApplicativeTaskValidation`](#getapplicativetaskvalidation) and [`getAltTaskValidation`](#getalttaskvalidation) instead.
- *
- * @category zone of death
- * @since 2.0.0
- * @deprecated
- */
- export declare function getTaskValidation<E>(
- SE: Semigroup<E>
- ): Monad2C<URI, E> & Bifunctor2<URI> & Alt2C<URI, E> & MonadTask2C<URI, E> & MonadThrow2C<URI, E>
|