TaskEither overview
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
.
Added in v2.0.0
Table of contents
- combinators
- constructors
- conversions
- do notation
- error handling
- filtering
- instances
- interop
- legacy
- bimap
- chain
- chainEitherK
- chainEitherKW
- chainFirst
- chainFirstEitherK
- chainFirstEitherKW
- chainFirstIOK
- chainFirstTaskK
- chainFirstW
- chainIOEitherK
- chainIOEitherKW
- chainIOK
- chainNullableK
- chainOptionK
- chainOptionKW
- chainTaskK
- chainTaskOptionK
- chainTaskOptionKW
- chainW
- fromNullableK
- fromOptionK
- mapLeft
- orElseFirst
- orElseFirstW
- lifting
- mapping
- model
- pattern matching
- sequencing
- traversing
- type lambdas
- utils
- zone of death
combinators
tap
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Signature
export declare const tap: {
<E1, A, E2, _>(self: TaskEither<E1, A>, f: (a: A) => TaskEither<E2, _>): TaskEither<E1 | E2, A>
<A, E2, _>(f: (a: A) => TaskEither<E2, _>): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
}
Added in v2.15.0
tapEither
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Signature
export declare const tapEither: {
<A, E2, _>(f: (a: A) => E.Either<E2, _>): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
<E1, A, E2, _>(self: TaskEither<E1, A>, f: (a: A) => E.Either<E2, _>): TaskEither<E1 | E2, A>
}
Example
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'
const checkString = (value: string) =>
pipe(
TE.of(value),
TE.tapEither(() => (value.length > 0 ? E.right('ok') : E.left('error')))
)
async function test() {
assert.deepStrictEqual(await checkString('')(), E.left('error'))
assert.deepStrictEqual(await checkString('fp-ts')(), E.right('fp-ts'))
}
test()
Added in v2.16.0
tapIO
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Signature
export declare const tapIO: {
<A, _>(f: (a: A) => IO<_>): <E>(self: TaskEither<E, A>) => TaskEither<E, A>
<E, A, _>(self: TaskEither<E, A>, f: (a: A) => IO<_>): TaskEither<E, A>
}
Example
import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'
import * as E from 'fp-ts/Either'
import * as Console from 'fp-ts/Console'
// Will produce `Hello, fp-ts` to the stdout
const effectA = TE.tapIO(TE.of(1), (value) => Console.log(`Hello, ${value}`))
// No output to the stdout
const effectB = pipe(
TE.left('error'),
TE.tapIO((value) => Console.log(`Hello, ${value}`))
)
async function test() {
assert.deepStrictEqual(await effectA(), E.of(1))
assert.deepStrictEqual(await effectB(), E.left('error'))
}
test()
Added in v2.16.0
tapTask
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Signature
export declare const tapTask: {
<A, _>(f: (a: A) => T.Task<_>): <E>(self: TaskEither<E, A>) => TaskEither<E, A>
<E, A, _>(self: TaskEither<E, A>, f: (a: A) => T.Task<_>): TaskEither<E, A>
}
Example
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
import * as E from 'fp-ts/Either'
const effect = TE.tapIO(TE.of(1), (value) => T.of(value + 1))
async function test() {
assert.deepStrictEqual(await effect(), E.of(1))
}
test()
Added in v2.16.0
constructors
left
Signature
export declare const left: <E = never, A = never>(e: E) => TaskEither<E, A>
Added in v2.0.0
leftIO
Signature
export declare const leftIO: <E = never, A = never>(me: IO<E>) => TaskEither<E, A>
Added in v2.0.0
leftTask
Signature
export declare const leftTask: <E = never, A = never>(me: T.Task<E>) => TaskEither<E, A>
Added in v2.0.0
of
Signature
export declare const of: <E = never, A = never>(a: A) => TaskEither<E, A>
Added in v2.0.0
right
Signature
export declare const right: <E = never, A = never>(a: A) => TaskEither<E, A>
Added in v2.0.0
rightIO
Signature
export declare const rightIO: <E = never, A = never>(ma: IO<A>) => TaskEither<E, A>
Added in v2.0.0
rightTask
Signature
export declare const rightTask: <E = never, A = never>(ma: T.Task<A>) => TaskEither<E, A>
Added in v2.0.0
conversions
fromEither
Signature
export declare const fromEither: <E, A>(fa: E.Either<E, A>) => TaskEither<E, A>
Added in v2.0.0
fromIO
Signature
export declare const fromIO: <A, E = never>(fa: IO<A>) => TaskEither<E, A>
Added in v2.7.0
fromIOEither
Signature
export declare const fromIOEither: <E, A>(fa: IOEither<E, A>) => TaskEither<E, A>
Added in v2.0.0
fromNullable
Signature
export declare const fromNullable: <E>(e: E) => <A>(a: A) => TaskEither<E, NonNullable<A>>
Added in v2.12.0
fromOption
Signature
export declare const fromOption: <E>(onNone: LazyArg<E>) => <A>(fa: Option<A>) => TaskEither<E, A>
Added in v2.0.0
fromTask
Signature
export declare const fromTask: <A, E = never>(fa: T.Task<A>) => TaskEither<E, A>
Added in v2.7.0
fromTaskOption
Signature
export declare const fromTaskOption: <E>(onNone: LazyArg<E>) => <A>(fa: TaskOption<A>) => TaskEither<E, A>
Added in v2.11.0
toUnion
Signature
export declare const toUnion: <E, A>(fa: TaskEither<E, A>) => T.Task<E | A>
Added in v2.10.0
do notation
Do
Signature
export declare const Do: TaskEither<never, {}>
Added in v2.9.0
apS
Signature
export declare const apS: <N, 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 }>
Added in v2.8.0
apSW
Less strict version of apS
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
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<E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
bind
Signature
export declare const bind: <N, 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 }>
Added in v2.8.0
bindTo
Signature
export declare const bindTo: <N>(name: N) => <E, A>(fa: TaskEither<E, A>) => TaskEither<E, { readonly [K in N]: A }>
Added in v2.8.0
bindW
The W
suffix (short for Widening) means that the error types will be merged.
Signature
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<E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
let
Signature
export declare const let: <N, 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 }>
Added in v2.13.0
error handling
alt
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.
Signature
export declare const alt: <E, A>(that: LazyArg<TaskEither<E, A>>) => (fa: TaskEither<E, A>) => TaskEither<E, A>
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()
Added in v2.0.0
altW
Less strict version of alt
.
The W
suffix (short for Widening) means that the error and the return types will be merged.
Signature
export declare const altW: <E2, B>(
that: LazyArg<TaskEither<E2, B>>
) => <E1, A>(fa: TaskEither<E1, A>) => TaskEither<E2, B | A>
Added in v2.9.0
getAltTaskValidation
The default 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
.
Signature
export declare function getAltTaskValidation<E>(S: Semigroup<E>): Alt2C<URI, E>
Added in v2.7.0
getApplicativeTaskValidation
The default 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
.
Signature
export declare function getApplicativeTaskValidation<E>(A: Apply1<T.URI>, S: Semigroup<E>): Applicative2C<URI, E>
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()
Added in v2.7.0
getOrElse
Signature
export declare const getOrElse: <E, A>(onLeft: (e: E) => T.Task<A>) => (ma: TaskEither<E, A>) => T.Task<A>
Added in v2.0.0
getOrElseW
Less strict version of getOrElse
.
The W
suffix (short for Widening) means that the handler return type will be merged.
Signature
export declare const getOrElseW: <E, B>(onLeft: (e: E) => T.Task<B>) => <A>(ma: TaskEither<E, A>) => T.Task<B | A>
Added in v2.6.0
mapBoth
Returns a TaskEither
whose failure and success channels have been mapped by the specified pair of functions, f
and g
.
Signature
export declare const mapBoth: {
<E, G, A, B>(f: (e: E) => G, g: (a: A) => B): (self: TaskEither<E, A>) => TaskEither<G, B>
<E, A, G, B>(self: TaskEither<E, A>, f: (e: E) => G, g: (a: A) => B): TaskEither<G, B>
}
Example
import * as TaskEither from 'fp-ts/TaskEither'
import * as Either from 'fp-ts/Either'
const f = (s: string) => new Error(s)
const g = (n: number) => n * 2
async function test() {
assert.deepStrictEqual(await TaskEither.mapBoth(TaskEither.right(1), f, g)(), Either.right(2))
assert.deepStrictEqual(await TaskEither.mapBoth(TaskEither.left('err'), f, g)(), Either.left(new Error('err')))
}
test()
Added in v2.16.0
mapError
Returns a TaskEither
with its error channel mapped using the specified function.
Signature
export declare const mapError: {
<E, G>(f: (e: E) => G): <A>(self: TaskEither<E, A>) => TaskEither<G, A>
<E, A, G>(self: TaskEither<E, A>, f: (e: E) => G): TaskEither<G, A>
}
Example
import * as TaskEither from 'fp-ts/TaskEither'
import * as Either from 'fp-ts/Either'
const f = (s: string) => new Error(s)
async function test() {
assert.deepStrictEqual(await TaskEither.mapError(TaskEither.right(1), f)(), Either.right(1))
assert.deepStrictEqual(await TaskEither.mapError(TaskEither.left('err'), f)(), Either.left(new Error('err')))
}
test()
Added in v2.16.0
orElse
Returns ma
if is a Right
or the value returned by onLeft
otherwise.
See also alt.
Signature
export declare const orElse: <E1, A, E2>(
onLeft: (e: E1) => TaskEither<E2, A>
) => (ma: TaskEither<E1, A>) => TaskEither<E2, A>
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()
Added in v2.0.0
orElseFirstIOK
Signature
export declare const orElseFirstIOK: <E, B>(onLeft: (e: E) => IO<B>) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.12.0
orElseFirstTaskK
Signature
export declare const orElseFirstTaskK: <E, B>(
onLeft: (e: E) => T.Task<B>
) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.12.0
orElseW
Less strict version of orElse
.
The W
suffix (short for Widening) means that the return types will be merged.
Signature
export declare const orElseW: <E1, E2, B>(
onLeft: (e: E1) => TaskEither<E2, B>
) => <A>(ma: TaskEither<E1, A>) => TaskEither<E2, B | A>
Added in v2.10.0
orLeft
Signature
export declare const orLeft: <E1, E2>(onLeft: (e: E1) => T.Task<E2>) => <A>(fa: TaskEither<E1, A>) => TaskEither<E2, A>
Added in v2.11.0
tapError
Returns an effect that effectfully “peeks” at the failure of this effect.
Signature
export declare const tapError: {
<E1, E2, _>(onLeft: (e: E1) => TaskEither<E2, _>): <A>(self: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
<E1, A, E2, _>(self: TaskEither<E1, A>, onLeft: (e: E1) => TaskEither<E2, _>): TaskEither<E1 | E2, A>
}
Added in v2.15.0
filtering
filterOrElse
Signature
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>
}
Added in v2.0.0
filterOrElseW
Less strict version of filterOrElse
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const filterOrElseW: {
<A, B extends A, E2>(refinement: Refinement<A, B>, onFalse: (a: A) => E2): <E1>(
ma: TaskEither<E1, A>
) => TaskEither<E2 | E1, B>
<A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1, B extends A>(
mb: TaskEither<E1, B>
) => TaskEither<E2 | E1, B>
<A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
}
Added in v2.9.0
getCompactable
Signature
export declare const getCompactable: <E>(M: Monoid<E>) => Compactable2C<'TaskEither', E>
Added in v2.10.0
getFilterable
Signature
export declare function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E>
Added in v2.1.0
instances
Alt
Signature
export declare const Alt: Alt2<'TaskEither'>
Added in v2.7.0
ApplicativePar
Runs computations in parallel.
Signature
export declare const ApplicativePar: Applicative2<'TaskEither'>
Added in v2.7.0
ApplicativeSeq
Runs computations sequentially.
Signature
export declare const ApplicativeSeq: Applicative2<'TaskEither'>
Added in v2.7.0
ApplyPar
Runs computations in parallel.
Signature
export declare const ApplyPar: Apply2<'TaskEither'>
Added in v2.10.0
ApplySeq
Runs computations sequentially.
Signature
export declare const ApplySeq: Apply2<'TaskEither'>
Added in v2.10.0
Bifunctor
Signature
export declare const Bifunctor: Bifunctor2<'TaskEither'>
Added in v2.7.0
Chain
Signature
export declare const Chain: chainable.Chain2<'TaskEither'>
Added in v2.10.0
FromEither
Signature
export declare const FromEither: FromEither2<'TaskEither'>
Added in v2.10.0
FromIO
Signature
export declare const FromIO: FromIO2<'TaskEither'>
Added in v2.10.0
FromTask
Signature
export declare const FromTask: FromTask2<'TaskEither'>
Added in v2.10.0
Functor
Signature
export declare const Functor: Functor2<'TaskEither'>
Added in v2.7.0
Monad
Signature
export declare const Monad: Monad2<'TaskEither'>
Added in v2.10.0
MonadIO
Signature
export declare const MonadIO: MonadIO2<'TaskEither'>
Added in v2.10.0
MonadTask
Signature
export declare const MonadTask: MonadTask2<'TaskEither'>
Added in v2.10.0
MonadThrow
Signature
export declare const MonadThrow: MonadThrow2<'TaskEither'>
Added in v2.10.0
Pointed
Signature
export declare const Pointed: Pointed2<'TaskEither'>
Added in v2.10.0
interop
taskify
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
// 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
)
Signature
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>
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)
Added in v2.0.0
tryCatch
Transforms a Promise
that may reject to a Promise
that never rejects and returns an Either
instead.
See also tryCatchK
.
Signature
export declare const tryCatch: <E, A>(f: LazyArg<Promise<A>>, onRejected: (reason: unknown) => E) => TaskEither<E, A>
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'))
})
Added in v2.0.0
tryCatchK
Converts a function returning a Promise
to one returning a TaskEither
.
Signature
export declare const tryCatchK: <E, A extends readonly unknown[], B>(
f: (...a: A) => Promise<B>,
onRejected: (reason: unknown) => E
) => (...a: A) => TaskEither<E, B>
Added in v2.5.0
legacy
bimap
Alias of mapBoth
.
Signature
export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: TaskEither<E, A>) => TaskEither<G, B>
Added in v2.0.0
chain
Alias of flatMap
.
Signature
export declare const chain: <E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.0.0
chainEitherK
Alias of flatMapEither
.
Signature
export declare const chainEitherK: <E, A, B>(f: (a: A) => E.Either<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.4.0
chainEitherKW
Alias of flatMapEither
.
Signature
export declare const chainEitherKW: <E2, A, B>(
f: (a: A) => E.Either<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.6.1
chainFirst
Alias of tap
.
Signature
export declare const chainFirst: <E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.0.0
chainFirstEitherK
Alias of tapEither
.
Signature
export declare const chainFirstEitherK: <A, E, B>(
f: (a: A) => E.Either<E, B>
) => (ma: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.12.0
chainFirstEitherKW
Alias of tapEither
.
Less strict version of chainFirstEitherK
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const chainFirstEitherKW: <A, E2, B>(
f: (a: A) => E.Either<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
Added in v2.12.0
chainFirstIOK
Alias of tapIO
.
Signature
export declare const chainFirstIOK: <A, B>(f: (a: A) => IO<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.10.0
chainFirstTaskK
Alias of tapTask
.
Signature
export declare const chainFirstTaskK: <A, B>(f: (a: A) => T.Task<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.10.0
chainFirstW
Alias of tap
.
Signature
export declare const chainFirstW: <E2, A, B>(
f: (a: A) => TaskEither<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
Added in v2.8.0
chainIOEitherK
Alias of flatMapIOEither
.
Signature
export declare const chainIOEitherK: <E, A, B>(
f: (a: A) => IOEither<E, B>
) => (ma: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.4.0
chainIOEitherKW
Alias of flatMapIOEither
.
Less strict version of chainIOEitherK
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const chainIOEitherKW: <E2, A, B>(
f: (a: A) => IOEither<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.6.1
chainIOK
Alias of flatMapIO
.
Signature
export declare const chainIOK: <A, B>(f: (a: A) => IO<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.10.0
chainNullableK
Use flatMapNullable
.
Signature
export declare const chainNullableK: <E>(
e: E
) => <A, B>(f: (a: A) => B | null | undefined) => (ma: TaskEither<E, A>) => TaskEither<E, NonNullable<B>>
Added in v2.12.0
chainOptionK
Use flatMapOption
.
Signature
export declare const chainOptionK: <E>(
onNone: LazyArg<E>
) => <A, B>(f: (a: A) => Option<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.10.0
chainOptionKW
Use flatMapOption
.
Signature
export declare const chainOptionKW: <E2>(
onNone: LazyArg<E2>
) => <A, B>(f: (a: A) => Option<B>) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.13.2
chainTaskK
Alias of flatMapTask
.
Signature
export declare const chainTaskK: <A, B>(f: (a: A) => T.Task<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.10.0
chainTaskOptionK
Use flatMapTaskOption
.
Signature
export declare const chainTaskOptionK: <E>(
onNone: LazyArg<E>
) => <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.11.0
chainTaskOptionKW
Use flatMapTaskOption
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const chainTaskOptionKW: <E2>(
onNone: LazyArg<E2>
) => <A, B>(f: (a: A) => TaskOption<B>) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.12.3
chainW
Alias of flatMap
.
Signature
export declare const chainW: <E2, A, B>(
f: (a: A) => TaskEither<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.6.0
fromNullableK
Use liftNullable
.
Signature
export declare const fromNullableK: <E>(
e: E
) => <A extends readonly unknown[], B>(
f: (...a: A) => B | null | undefined
) => (...a: A) => TaskEither<E, NonNullable<B>>
Added in v2.12.0
fromOptionK
Use liftOption
.
Signature
export declare const fromOptionK: <E>(
onNone: LazyArg<E>
) => <A extends readonly unknown[], B>(f: (...a: A) => Option<B>) => (...a: A) => TaskEither<E, B>
Added in v2.10.0
mapLeft
Alias of mapError
.
Signature
export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: TaskEither<E, A>) => TaskEither<G, A>
Added in v2.0.0
orElseFirst
Alias of tapError
.
Signature
export declare const orElseFirst: <E, B>(
onLeft: (e: E) => TaskEither<E, B>
) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.11.0
orElseFirstW
Alias of tapError
.
Signature
export declare const orElseFirstW: <E1, E2, B>(
onLeft: (e: E1) => TaskEither<E2, B>
) => <A>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
Added in v2.11.0
lifting
fromEitherK
Signature
export declare const fromEitherK: <E, A extends readonly unknown[], B>(
f: (...a: A) => E.Either<E, B>
) => (...a: A) => TaskEither<E, B>
Added in v2.4.0
fromIOEitherK
Signature
export declare const fromIOEitherK: <E, A extends readonly unknown[], B>(
f: (...a: A) => IOEither<E, B>
) => (...a: A) => TaskEither<E, B>
Added in v2.4.0
fromIOK
Signature
export declare const fromIOK: <A extends readonly unknown[], B>(
f: (...a: A) => IO<B>
) => <E = never>(...a: A) => TaskEither<E, B>
Added in v2.10.0
fromPredicate
Signature
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>
}
Added in v2.0.0
fromTaskK
Signature
export declare const fromTaskK: <A extends readonly unknown[], B>(
f: (...a: A) => T.Task<B>
) => <E = never>(...a: A) => TaskEither<E, B>
Added in v2.10.0
fromTaskOptionK
Signature
export declare const fromTaskOptionK: <E>(
onNone: LazyArg<E>
) => <A extends readonly unknown[], B>(f: (...a: A) => TaskOption<B>) => (...a: A) => TaskEither<E, B>
Added in v2.11.0
liftNullable
Signature
export declare const liftNullable: <A extends readonly unknown[], B, E>(
f: (...a: A) => B | null | undefined,
onNullable: (...a: A) => E
) => (...a: A) => TaskEither<E, NonNullable<B>>
Added in v2.15.0
liftOption
Signature
export declare const liftOption: <A extends readonly unknown[], B, E>(
f: (...a: A) => Option<B>,
onNone: (...a: A) => E
) => (...a: A) => TaskEither<E, B>
Added in v2.15.0
mapping
as
Maps the Right
value of this TaskEither
to the specified constant value.
Signature
export declare const as: {
<A>(a: A): <E, _>(self: TaskEither<E, _>) => TaskEither<E, A>
<E, _, A>(self: TaskEither<E, _>, a: A): TaskEither<E, A>
}
Added in v2.16.0
asUnit
Maps the Right
value of this TaskEither
to the void constant value.
Signature
export declare const asUnit: <E, _>(self: TaskEither<E, _>) => TaskEither<E, void>
Added in v2.16.0
flap
Signature
export declare const flap: <A>(a: A) => <E, B>(fab: TaskEither<E, (a: A) => B>) => TaskEither<E, B>
Added in v2.10.0
map
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.
Signature
export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.0.0
model
TaskEither (interface)
Signature
export interface TaskEither<E, A> extends Task<Either<E, A>> {}
Added in v2.0.0
pattern matching
fold
Alias of matchE
.
Signature
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>
Added in v2.0.0
foldW
Alias of matchEW
.
Signature
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>
Added in v2.10.0
match
Signature
export declare const match: <E, B, A>(onLeft: (e: E) => B, onRight: (a: A) => B) => (ma: TaskEither<E, A>) => T.Task<B>
Added in v2.10.0
matchE
The E
suffix (short for Effect) means that the handlers return an effect (Task
).
Signature
export declare const matchE: <E, A, B>(
onLeft: (e: E) => T.Task<B>,
onRight: (a: A) => T.Task<B>
) => (ma: TaskEither<E, A>) => T.Task<B>
Added in v2.10.0
matchEW
Less strict version of matchE
.
The W
suffix (short for Widening) means that the handler return types will be merged.
Signature
export declare const matchEW: <E, B, A, C>(
onLeft: (e: E) => T.Task<B>,
onRight: (a: A) => T.Task<C>
) => (ma: TaskEither<E, A>) => T.Task<B | C>
Added in v2.10.0
matchW
Less strict version of match
.
The W
suffix (short for Widening) means that the handler return types will be merged.
Signature
export declare const matchW: <E, B, A, C>(
onLeft: (e: E) => B,
onRight: (a: A) => C
) => (ma: TaskEither<E, A>) => T.Task<B | C>
Added in v2.10.0
sequencing
flatMap
Signature
export declare const flatMap: {
<A, E2, B>(f: (a: A) => TaskEither<E2, B>): <E1>(ma: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
<E1, A, E2, B>(ma: TaskEither<E1, A>, f: (a: A) => TaskEither<E2, B>): TaskEither<E1 | E2, B>
}
Added in v2.14.0
flatMapEither
Signature
export declare const flatMapEither: {
<A, E2, B>(f: (a: A) => E.Either<E2, B>): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
<E1, A, E2, B>(self: TaskEither<E1, A>, f: (a: A) => E.Either<E2, B>): TaskEither<E1 | E2, B>
}
Added in v2.15.0
flatMapIO
Signature
export declare const flatMapIO: {
<A, B>(f: (a: A) => IO<B>): <E>(self: TaskEither<E, A>) => TaskEither<E, B>
<E, A, B>(self: TaskEither<E, A>, f: (a: A) => IO<B>): TaskEither<E, B>
}
Added in v2.15.0
flatMapIOEither
Signature
export declare const flatMapIOEither: {
<A, E2, B>(f: (a: A) => IOEither<E2, B>): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
<E1, A, E2, B>(self: TaskEither<E1, A>, f: (a: A) => IOEither<E2, B>): TaskEither<E1 | E2, B>
}
Added in v2.16.0
flatMapNullable
Signature
export declare const flatMapNullable: {
<A, B, E2>(f: (a: A) => B | null | undefined, onNullable: (a: A) => E2): <E1>(
self: TaskEither<E1, A>
) => TaskEither<E2 | E1, NonNullable<B>>
<E1, A, B, E2>(self: TaskEither<E1, A>, f: (a: A) => B | null | undefined, onNullable: (a: A) => E2): TaskEither<
E1 | E2,
NonNullable<B>
>
}
Added in v2.15.0
flatMapOption
Signature
export declare const flatMapOption: {
<A, B, E2>(f: (a: A) => Option<B>, onNone: (a: A) => E2): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
<E1, A, B, E2>(self: TaskEither<E1, A>, f: (a: A) => Option<B>, onNone: (a: A) => E2): TaskEither<E1 | E2, B>
}
Added in v2.15.0
flatMapTask
Signature
export declare const flatMapTask: {
<A, B>(f: (a: A) => T.Task<B>): <E>(self: TaskEither<E, A>) => TaskEither<E, B>
<E, A, B>(self: TaskEither<E, A>, f: (a: A) => T.Task<B>): TaskEither<E, B>
}
Added in v2.16.0
flatMapTaskOption
Signature
export declare const flatMapTaskOption: {
<A, E2, B>(f: (a: A) => TaskOption<B>, onNone: (a: A) => E2): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
<E1, A, E2, B>(self: TaskEither<E1, A>, f: (a: A) => TaskOption<B>, onNone: (a: A) => E2): TaskEither<E1 | E2, B>
}
Added in v2.16.0
flatten
Signature
export declare const flatten: <E, A>(mma: TaskEither<E, TaskEither<E, A>>) => TaskEither<E, A>
Added in v2.0.0
flattenW
Less strict version of flatten
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const flattenW: <E1, E2, A>(mma: TaskEither<E1, TaskEither<E2, A>>) => TaskEither<E1 | E2, A>
Added in v2.11.0
traversing
sequenceArray
Equivalent to ReadonlyArray#sequence(Applicative)
.
Signature
export declare const sequenceArray: <A, E>(arr: readonly TaskEither<E, A>[]) => TaskEither<E, readonly A[]>
Added in v2.9.0
sequenceSeqArray
Equivalent to ReadonlyArray#sequence(ApplicativeSeq)
.
Signature
export declare const sequenceSeqArray: <A, E>(arr: readonly TaskEither<E, A>[]) => TaskEither<E, readonly A[]>
Added in v2.9.0
traverseArray
Equivalent to ReadonlyArray#traverse(Applicative)
.
Signature
export declare const traverseArray: <A, B, E>(
f: (a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.9.0
traverseArrayWithIndex
Equivalent to ReadonlyArray#traverseWithIndex(Applicative)
.
Signature
export declare const traverseArrayWithIndex: <A, B, E>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.9.0
traverseReadonlyArrayWithIndex
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativePar)
.
Signature
export declare const traverseReadonlyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.11.0
traverseReadonlyArrayWithIndexSeq
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq)
.
Signature
export declare const traverseReadonlyArrayWithIndexSeq: <A, E, B>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.11.0
traverseReadonlyNonEmptyArrayWithIndex
Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)
.
Signature
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => TaskEither<E, ReadonlyNonEmptyArray<B>>
Added in v2.11.0
traverseReadonlyNonEmptyArrayWithIndexSeq
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq)
.
Signature
export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: <A, E, B>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => TaskEither<E, ReadonlyNonEmptyArray<B>>
Added in v2.11.0
traverseSeqArray
Equivalent to ReadonlyArray#traverse(ApplicativeSeq)
.
Signature
export declare const traverseSeqArray: <A, B, E>(
f: (a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.9.0
traverseSeqArrayWithIndex
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq)
.
Signature
export declare const traverseSeqArrayWithIndex: <A, B, E>(
f: (index: number, a: A) => TaskEither<E, B>
) => (as: readonly A[]) => TaskEither<E, readonly B[]>
Added in v2.9.0
type lambdas
URI
Signature
export declare const URI: 'TaskEither'
Added in v2.0.0
URI (type alias)
Signature
export type URI = typeof URI
Added in v2.0.0
utils
ApT
Signature
export declare const ApT: TaskEither<never, readonly []>
Added in v2.11.0
ap
Signature
export declare const ap: <E, A>(fa: TaskEither<E, A>) => <B>(fab: TaskEither<E, (a: A) => B>) => TaskEither<E, B>
Added in v2.0.0
apFirst
Combine two effectful actions, keeping only the result of the first.
Signature
export declare const apFirst: <E, B>(second: TaskEither<E, B>) => <A>(first: TaskEither<E, A>) => TaskEither<E, A>
Added in v2.0.0
apFirstW
Less strict version of apFirst
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const apFirstW: <E2, B>(
second: TaskEither<E2, B>
) => <E1, A>(first: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
Added in v2.12.0
apSecond
Combine two effectful actions, keeping only the result of the second.
Signature
export declare const apSecond: <E, B>(second: TaskEither<E, B>) => <A>(first: TaskEither<E, A>) => TaskEither<E, B>
Added in v2.0.0
apSecondW
Less strict version of apSecond
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const apSecondW: <E2, B>(
second: TaskEither<E2, B>
) => <E1, A>(first: TaskEither<E1, A>) => TaskEither<E2 | E1, B>
Added in v2.12.0
apW
Less strict version of ap
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
export declare const apW: <E2, A>(
fa: TaskEither<E2, A>
) => <E1, B>(fab: TaskEither<E1, (a: A) => B>) => TaskEither<E2 | E1, B>
Added in v2.8.0
bracket
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
Signature
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>
Added in v2.0.0
bracketW
Less strict version of bracket
.
The W
suffix (short for Widening) means that the error types will be merged.
Signature
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>
Added in v2.12.0
swap
Signature
export declare const swap: <E, A>(ma: TaskEither<E, A>) => TaskEither<A, E>
Added in v2.0.0
throwError
Signature
export declare const throwError: <E, A>(e: E) => TaskEither<E, A>
Added in v2.7.0
zone of death
getApplyMonoid
Use getApplicativeMonoid
instead.
Signature
export declare const getApplyMonoid: <E, A>(M: Monoid<A>) => Monoid<TaskEither<E, A>>
Added in v2.0.0
getApplySemigroup
Use getApplySemigroup
instead.
Signature
export declare const getApplySemigroup: <E, A>(S: Semigroup<A>) => Semigroup<TaskEither<E, A>>
Added in v2.0.0
getSemigroup
Use getApplySemigroup
instead.
Signature
export declare const getSemigroup: <E, A>(S: Semigroup<A>) => Semigroup<TaskEither<E, A>>
Added in v2.0.0
getTaskValidation
Use getApplicativeTaskValidation
and getAltTaskValidation
instead.
Signature
export declare function getTaskValidation<E>(
SE: Semigroup<E>
): Monad2C<URI, E> & Bifunctor2<URI> & Alt2C<URI, E> & MonadTask2C<URI, E> & MonadThrow2C<URI, E>
Added in v2.0.0
taskEitherSeq
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'
)
Signature
export declare const taskEitherSeq: Monad2<'TaskEither'> &
Bifunctor2<'TaskEither'> &
Alt2<'TaskEither'> &
MonadTask2<'TaskEither'> &
MonadThrow2<'TaskEither'>
Added in v2.0.0
taskEither
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'
)
Signature
export declare const taskEither: Monad2<'TaskEither'> &
Bifunctor2<'TaskEither'> &
Alt2<'TaskEither'> &
MonadTask2<'TaskEither'> &
MonadThrow2<'TaskEither'>
Added in v2.0.0