Overview

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.


Table of contents


TaskEither (interface)

Signature

export interface TaskEither<E, A> extends Task<Either<E, A>> {}

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

URI (constant)

Signature

export const URI: "TaskEither" = ...

Added in v2.0.0

fromIOEither (constant)

Signature

export const fromIOEither: <E, A>(fa: IOEither<E, A>) => TaskEither<E, A> = ...

Added in v2.0.0

left (constant)

Signature

export const left: <E = ...

Added in v2.0.0

leftTask (constant)

Signature

export const leftTask: <E = ...

Added in v2.0.0

right (constant)

Signature

export const right: <E = ...

Added in v2.0.0

rightTask (constant)

Signature

export const rightTask: <E = ...

Added in v2.0.0

swap (constant)

Signature

export const swap: <E, A>(ma: TaskEither<E, A>) => TaskEither<A, E> = ...

Added in v2.0.0

taskEither (constant)

Signature

export const taskEither: Monad2<URI> & Bifunctor2<URI> & Alt2<URI> & MonadTask2<URI> & MonadThrow2<URI> = ...

Added in v2.0.0

taskEitherSeq (constant)

Like TaskEither but ap is sequential

Signature

export const taskEitherSeq: typeof taskEither = ...

Added in v2.0.0

bracket (function)

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.

Signature

export function bracket<E, A, B>(
  acquire: TaskEither<E, A>,
  use: (a: A) => TaskEither<E, B>,
  release: (a: A, e: Either<E, B>) => TaskEither<E, void>
): TaskEither<E, B> { ... }

Added in v2.0.0

fold (function)

Signature

export function fold<E, A, B>(
  onLeft: (e: E) => Task<B>,
  onRight: (a: A) => Task<B>
): (ma: TaskEither<E, A>) => Task<B> { ... }

Added in v2.0.0

getApplyMonoid (function)

Signature

export function getApplyMonoid<E, A>(M: Monoid<A>): Monoid<TaskEither<E, A>> { ... }

Added in v2.0.0

getApplySemigroup (function)

Signature

export function getApplySemigroup<E, A>(S: Semigroup<A>): Semigroup<TaskEither<E, A>> { ... }

Added in v2.0.0

getFilterable (function)

Signature

export function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E> { ... }

Added in v2.1.0

getOrElse (function)

Signature

export function getOrElse<E, A>(onLeft: (e: E) => Task<A>): (ma: TaskEither<E, A>) => Task<A> { ... }

Added in v2.0.0

getSemigroup (function)

Signature

export function getSemigroup<E, A>(S: Semigroup<A>): Semigroup<TaskEither<E, A>> { ... }

Added in v2.0.0

getTaskValidation (function)

Signature

export function getTaskValidation<E>(S: Semigroup<E>): Monad2C<URI, E> & Alt2C<URI, E> { ... }

Added in v2.0.0

leftIO (function)

Signature

export function leftIO<E = never, A = never>(me: IO<E>): TaskEither<E, A> { ... }

Added in v2.0.0

orElse (function)

Signature

export function orElse<E, A, M>(onLeft: (e: E) => TaskEither<M, A>): (ma: TaskEither<E, A>) => TaskEither<M, A> { ... }

Added in v2.0.0

rightIO (function)

Signature

export function rightIO<E = never, A = never>(ma: IO<A>): TaskEither<E, A> { ... }

Added in v2.0.0

taskify (function)

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 function taskify<L, R>(f: (cb: (e: L | null | undefined, r?: R) => void) => void): () => TaskEither<L, R>
export function taskify<A, L, R>(
  f: (a: A, cb: (e: L | null | undefined, r?: R) => void) => void
): (a: A) => TaskEither<L, R>
export 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 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 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 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/lib/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 (function)

Signature

export function tryCatch<E, A>(f: Lazy<Promise<A>>, onRejected: (reason: unknown) => E): TaskEither<E, A> { ... }

Added in v2.0.0

alt (export)

Signature

<E, A>(that: () => TaskEither<E, A>) => (fa: TaskEither<E, A>) => TaskEither<E, A>

Added in v2.0.0

ap (export)

Signature

<E, A>(fa: TaskEither<E, A>) => <B>(fab: TaskEither<E, (a: A) => B>) => TaskEither<E, B>

Added in v2.0.0

apFirst (export)

Signature

<E, B>(fb: TaskEither<E, B>) => <A>(fa: TaskEither<E, A>) => TaskEither<E, A>

Added in v2.0.0

apSecond (export)

Signature

<E, B>(fb: TaskEither<E, B>) => <A>(fa: TaskEither<E, A>) => TaskEither<E, B>

Added in v2.0.0

bimap (export)

Signature

<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 (export)

Signature

<E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>

Added in v2.0.0

chainFirst (export)

Signature

<E, A, B>(f: (a: A) => TaskEither<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, A>

Added in v2.0.0

filterOrElse (export)

Signature

{ <E, A, B>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (ma: TaskEither<E, A>) => TaskEither<E, B>; <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (ma: TaskEither<E, A>) => TaskEither<E, A>; }

Added in v2.0.0

flatten (export)

Signature

<E, A>(mma: TaskEither<E, TaskEither<E, A>>) => TaskEither<E, A>

Added in v2.0.0

fromEither (export)

Signature

<E, A>(ma: E.Either<E, A>) => TaskEither<E, A>

Added in v2.0.0

fromOption (export)

Signature

<E>(onNone: () => E) => <A>(ma: Option<A>) => TaskEither<E, A>

Added in v2.0.0

fromPredicate (export)

Signature

{ <E, A, B>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => TaskEither<E, B>; <E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => TaskEither<E, A>; }

Added in v2.0.0

map (export)

Signature

<A, B>(f: (a: A) => B) => <E>(fa: TaskEither<E, A>) => TaskEither<E, B>

Added in v2.0.0

mapLeft (export)

Signature

<E, G>(f: (e: E) => G) => <A>(fa: TaskEither<E, A>) => TaskEither<G, A>

Added in v2.0.0