IOEither overview

Utility functions to accommodate fp-ts/IOEither.

Added in v0.15.0


Table of contents


2 Typeclass Methods

pass

Convenient alias for IOE.of(undefined).

Signature

export declare const pass: IOEither<never, void>
pass :: IOEither 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 IOE from 'fp-ts/IOEither'
import IOEither = IOE.IOEither
import { pass } from 'fp-ts-std/IOEither'
import { log } from 'fp-ts/Console'

const mcount: Option<number> = O.some(123)
const tryLog: <A>(x: A) => IOEither<void, void> = flow(log, IOE.fromIO)

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

Added in v0.17.0

sequenceArray_

Sequence an array of fallible effects, ignoring the results.

Signature

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

Added in v0.15.0

traverseArray_

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

Signature

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

Added in v0.15.0

3 Functions

unsafeExpect

Unwrap the value from within an IOEither, throwing the inner value of Left via Show if Left.

Signature

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

Example

import { unsafeExpect } from 'fp-ts-std/IOEither'
import * as IOE from 'fp-ts/IOEither'
import * as Str from 'fp-ts/string'

assert.throws(() => unsafeExpect(Str.Show)(IOE.left('foo')), Error('Unwrapped `Left`', { cause: '"foo"' }))

Added in v0.16.0

unsafeExpectLeft

Unwrap the value from within an IOEither, throwing the inner value of Right via Show if Right.

Signature

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

Example

import { unsafeExpectLeft } from 'fp-ts-std/IOEither'
import * as IOE from 'fp-ts/IOEither'
import * as Str from 'fp-ts/string'

assert.throws(() => unsafeExpectLeft(Str.Show)(IOE.right('foo')), Error('Unwrapped `Right`', { cause: '"foo"' }))

Added in v0.16.0

unsafeUnwrap

Unwrap the value from within an IOEither, throwing with the inner value of Left if Left.

Signature

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

Example

import { unsafeUnwrap } from 'fp-ts-std/IOEither'
import * as IOE from 'fp-ts/IOEither'

assert.strictEqual(unsafeUnwrap(IOE.right(5)), 5)

Added in v0.15.0

unsafeUnwrapLeft

Unwrap the value from within an IOEither, throwing the inner value of Right if Right.

Signature

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

Example

import { unsafeUnwrapLeft } from 'fp-ts-std/IOEither'
import * as IOE from 'fp-ts/IOEither'

assert.strictEqual(unsafeUnwrapLeft(IOE.left(5)), 5)

Added in v0.15.0