TaskEither overview

Utility functions to accommodate fp-ts/TaskEither.

Added in v0.12.0


Table of contents


2 Typeclass Methods

pass

Convenient alias for TE.of(undefined).

Signature

export declare const pass: TaskEither<never, void>
pass :: TaskEither never void

Example

import { flow, pipe, constant } from 'fp-ts/function'
import * as Fn from 'fp-ts-std/Function'
import * as O from 'fp-ts/Option'
import Option = O.Option
import * as TE from 'fp-ts/TaskEither'
import TaskEither = TE.TaskEither
import { pass } from 'fp-ts-std/TaskEither'
import { log } from 'fp-ts/Console'

const mcount: Option<number> = O.some(123)
const tryAsyncLog: <A>(x: A) => TaskEither<void, void> = flow(log, TE.fromIO)

const logCount: TaskEither<void, void> = pipe(mcount, O.match(constant(pass), tryAsyncLog))

Added in v0.17.0

sequenceArray_

Sequence an array of fallible tasks, ignoring the results.

Signature

export declare const sequenceArray_: <E, A>(xs: readonly TaskEither<E, A>[]) => TaskEither<E, void>
sequenceArray_ :: Array (TaskEither e a) -> TaskEither e void

Added in v0.15.0

sequenceSeqArray_

Sequentially sequence an array of fallible tasks, ignoring the results.

Signature

export declare const sequenceSeqArray_: <E, A>(xs: readonly TaskEither<E, A>[]) => TaskEither<E, void>
sequenceSeqArray_ :: Array (TaskEither e a) -> TaskEither e void

Added in v0.15.0

traverseArray_

Map to and sequence an array of fallible tasks, ignoring the results.

Signature

export declare const traverseArray_: <E, A, B>(
  f: (x: A) => TaskEither<E, B>
) => (xs: readonly A[]) => TaskEither<E, void>
traverseArray_ :: (a -> TaskEither e b) -> Array a -> TaskEither e void

Added in v0.15.0

traverseSeqArray_

Sequentially map to and sequence an array of fallible tasks, ignoring the results.

Signature

export declare const traverseSeqArray_: <E, A, B>(
  f: (x: A) => TaskEither<E, B>
) => (xs: readonly A[]) => TaskEither<E, void>
traverseSeqArray_ :: (a -> TaskEither e b) -> Array a -> TaskEither e void

Added in v0.15.0

3 Functions

unsafeExpect

Unwrap the promise from within a TaskEither, rejecting with the inner value of Left via Show if Left.

Signature

export declare const unsafeExpect: <E>(S: Show<E>) => <A>(x: TaskEither<E, A>) => Promise<A>
unsafeExpect :: Show e -> TaskEither e a -> Promise a

Example

import { unsafeExpect } from 'fp-ts-std/TaskEither'
import * as TE from 'fp-ts/TaskEither'
import * as Str from 'fp-ts/string'

assert.rejects(unsafeExpect(Str.Show)(TE.left('foo')), Error('Unwrapped `Left`', { cause: 'foo' }))

Added in v0.16.0

unsafeExpectLeft

Unwrap the promise from within a TaskEither, rejecting with the inner value of Right via Show if Right.

Signature

export declare const unsafeExpectLeft: <A>(S: Show<A>) => <E>(x: TaskEither<E, A>) => Promise<E>
unsafeExpectLeft :: Show a -> TaskEither e a -> Promise e

Example

import { unsafeExpectLeft } from 'fp-ts-std/TaskEither'
import * as TE from 'fp-ts/TaskEither'
import * as Str from 'fp-ts/string'

assert.rejects(unsafeExpectLeft(Str.Show)(TE.right('foo')), Error('Unwrapped `Right`', { cause: '"foo"' }))

Added in v0.16.0

unsafeUnwrap

Unwrap the promise from within a TaskEither, rejecting with the inner value of Left if Left.

Signature

export declare const unsafeUnwrap: <A>(x: TaskEither<unknown, A>) => Promise<A>
unsafeUnwrap :: TaskEither unknown a -> Promise a

Example

import { unsafeUnwrap } from 'fp-ts-std/TaskEither'
import * as TE from 'fp-ts/TaskEither'

unsafeUnwrap(TE.right(5)).then((x) => {
  assert.strictEqual(x, 5)
})

Added in v0.12.0

unsafeUnwrapLeft

Unwrap the promise from within a TaskEither, throwing the inner value of Right if Right.

Signature

export declare const unsafeUnwrapLeft: <E>(x: TaskEither<E, unknown>) => Promise<E>
unsafeUnwrapLeft :: TaskEither e unknown -> Promise e

Example

import { unsafeUnwrapLeft } from 'fp-ts-std/TaskEither'
import * as TE from 'fp-ts/TaskEither'

unsafeUnwrapLeft(TE.left(5)).then((x) => {
  assert.strictEqual(x, 5)
})

Added in v0.12.0