TaskEither
Instances
- Alt
- ApplicativePar
- ApplicativeSeq
- ApplyPar
- ApplySeq
- Bifunctor
- Chain
- ChainRec
- FromEither
- FromIO
- FromTask
- Functor
- Monad
- MonadIO
- MonadTask
- MonadThrow
- Pointed
Combinators
Constructors
Conversions
Do notation
Error handling
- alt
- altW
- getAltTaskValidation
- getApplicativeTaskValidation
- getOrElse
- getOrElseW
- mapBoth
- mapError
- orElse
- orElseFirstIOK
- orElseFirstTaskK
- orElseW
- orLeft
- tapError
Filtering
Instance methods
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
- flatMap
- flatMapEither
- flatMapIO
- flatMapIOEither
- flatMapNullable
- flatMapOption
- flatMapTask
- flatMapTaskOption
- flatten
- flattenW
Traversing
- sequenceArray
- sequenceSeqArray
- traverseArray
- traverseArrayWithIndex
- traverseReadonlyArrayWithIndex
- traverseReadonlyArrayWithIndexSeq
- traverseReadonlyNonEmptyArrayWithIndex
- traverseReadonlyNonEmptyArrayWithIndexSeq
- traverseSeqArray
- traverseSeqArrayWithIndex
Type lambdas
Utilities
- ApT
- ap
- apFirst
- apFirstW
- apSecond
- apSecondW
- apW
- bracket
- bracketW
- do
getApplyMonoid(deprecated)getApplySemigroup(deprecated)getSemigroup(deprecated)getTaskValidation(deprecated)- let
- swap
taskEither(deprecated)taskEitherSeq(deprecated)- throwError
Instances
Alt
Signature
export declare const Alt: Alt2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
ApplicativePar
Runs computations in parallel.
Signature
export declare const ApplicativePar: Applicative2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
ApplicativeSeq
Runs computations sequentially.
Signature
export declare const ApplicativeSeq: Applicative2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
ApplyPar
Runs computations in parallel.
Signature
export declare const ApplyPar: Apply2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
ApplySeq
Runs computations sequentially.
Signature
export declare const ApplySeq: Apply2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Bifunctor
Signature
export declare const Bifunctor: Bifunctor2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Chain
Signature
export declare const Chain: chainable.Chain2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
ChainRec
ChainRec for TaskEither
Signature
export declare const ChainRec: ChainRec2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2022-present Jacob Alford
FromEither
Signature
export declare const FromEither: FromEither2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
FromIO
Signature
export declare const FromIO: FromIO2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
FromTask
Signature
export declare const FromTask: FromTask2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Functor
Signature
export declare const Functor: Functor2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Monad
Signature
export declare const Monad: Monad2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
MonadIO
Signature
export declare const MonadIO: MonadIO2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
MonadTask
Signature
export declare const MonadTask: MonadTask2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
MonadThrow
Signature
export declare const MonadThrow: MonadThrow2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Pointed
Signature
export declare const Pointed: Pointed2<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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) => Either<E2, _>): <E1>(self: TaskEither<E1, A>) => TaskEither<E2 | E1, A>
<E1, A, E2, _>(self: TaskEither<E1, A>, f: (a: A) => Either<E2, _>): TaskEither<E1 | E2, A>
}
Details
- Added in 0.1.0
Example
import * as E from '@fp-tx/core/Either'
import { pipe } from '@fp-tx/core/function'
import * as TE from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
Example
import { pipe } from '@fp-tx/core/function'
import * as TE from '@fp-tx/core/TaskEither'
import * as E from '@fp-tx/core/Either'
import * as Console from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
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) => Task<_>): <E>(self: TaskEither<E, A>) => TaskEither<E, A>
<E, A, _>(self: TaskEither<E, A>, f: (a: A) => Task<_>): TaskEither<E, A>
}
Details
- Added in 0.1.0
Example
import * as TE from '@fp-tx/core/TaskEither'
import * as T from '@fp-tx/core/Task'
import * as E from '@fp-tx/core/Either'
const effect = TE.tapIO(TE.of(1), value => T.of(value + 1))
async function test() {
assert.deepStrictEqual(await effect(), E.of(1))
}
test()
License
- MIT – Copyright (c) 2017-present Giulio Canti
Constructors
left
Signature
export declare const left: <E = never, A = never>(e: E) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
leftIO
Signature
export declare const leftIO: <E = never, A = never>(me: IO<E>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
leftTask
Signature
export declare const leftTask: <E = never, A = never>(me: Task<E>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
of
Signature
export declare const of: <E = never, A = never>(a: A) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
right
Signature
export declare const right: <E = never, A = never>(a: A) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
rightIO
Signature
export declare const rightIO: <E = never, A = never>(ma: IO<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
rightTask
Signature
export declare const rightTask: <E = never, A = never>(ma: Task<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Conversions
fromEither
Signature
export declare const fromEither: <E, A>(fa: Either<E, A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromIO
Signature
export declare const fromIO: <A, E = never>(fa: IO<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromIOEither
Signature
export declare const fromIOEither: <E, A>(fa: IOEither<E, A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromNullable
Signature
export declare const fromNullable: <E>(e: E) => <A>(a: A) => TaskEither<E, NonNullable<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromOption
Signature
export declare const fromOption: <E>(onNone: LazyArg<E>) => <A>(fa: Option<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromTask
Signature
export declare const fromTask: <A, E = never>(fa: Task<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromTaskOption
Signature
export declare const fromTaskOption: <E>(onNone: LazyArg<E>) => <A>(fa: TaskOption<A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
toUnion
Signature
export declare const toUnion: <E, A>(fa: TaskEither<E, A>) => Task<E | A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Do notation
Do
Signature
export declare const Do: TaskEither<never, {}>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
apS
Signature
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 }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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<
E1 | E2,
{
readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
}
>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
bind
Signature
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 }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
bindTo
Signature
export declare const bindTo: <N extends string>(
name: N,
) => <E, A>(fa: TaskEither<E, A>) => TaskEither<E, { readonly [K in N]: A }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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<
E1 | E2,
{
readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
}
>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
Example
import * as E from '@fp-tx/core/Either'
import { pipe } from '@fp-tx/core/function'
import * as TE from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
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, A | B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
Example
import * as E from '@fp-tx/core/Either'
import { pipe } from '@fp-tx/core/function'
import * as RA from '@fp-tx/core/ReadonlyArray'
import * as S from '@fp-tx/core/Semigroup'
import * as string from '@fp-tx/core/string'
import * as T from '@fp-tx/core/Task'
import * as TE from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
getOrElse
Signature
export declare const getOrElse: <E, A>(onLeft: (e: E) => Task<A>) => (ma: TaskEither<E, A>) => Task<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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) => Task<B>) => <A>(ma: TaskEither<E, A>) => Task<A | B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
Example
import * as TaskEither from '@fp-tx/core/TaskEither'
import * as Either from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
Example
import * as TaskEither from '@fp-tx/core/TaskEither'
import * as Either from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
Example
import * as E from '@fp-tx/core/Either'
import { pipe } from '@fp-tx/core/function'
import * as TE from '@fp-tx/core/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()
License
- MIT – Copyright (c) 2017-present Giulio Canti
orElseFirstIOK
Signature
export declare const orElseFirstIOK: <E, B>(onLeft: (e: E) => IO<B>) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
orElseFirstTaskK
Signature
export declare const orElseFirstTaskK: <E, B>(
onLeft: (e: E) => Task<B>,
) => <A>(ma: TaskEither<E, A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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, A | B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
orLeft
Signature
export declare const orLeft: <E1, E2>(onLeft: (e: E1) => Task<E2>) => <A>(fa: TaskEither<E1, A>) => TaskEither<E2, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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<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>
}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
getCompactable
Signature
export declare const getCompactable: <E>(M: Monoid<E>) => Compactable2C<'TaskEither', E>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
getFilterable
Signature
export declare function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Instance methods
chainRec
Signature
export declare const chainRec: ChainRec2<URI>['chainRec']
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2022-present Jacob Alford
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>
Details
- Added in 0.1.0
Example
import { taskify } from '@fp-tx/core/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)
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
Example
import { left, right } from '@fp-tx/core/Either'
import { tryCatch } from '@fp-tx/core/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'))
})
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
chainEitherKW
Alias of flatMapEither
.
Signature
export declare const chainEitherKW: <E2, A, B>(
f: (a: A) => Either<E2, B>,
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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<E1 | E2, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
chainFirstIOK
Alias of tapIO
.
Signature
export declare const chainFirstIOK: <A, B>(f: (a: A) => IO<B>) => <E>(first: TaskEither<E, A>) => TaskEither<E, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
chainFirstW
Alias of tap
.
Signature
export declare const chainFirstW: <E2, A, B>(
f: (a: A) => TaskEither<E2, B>,
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti