ReaderEither overview

Utility functions to accommodate fp-ts/ReaderEither.

Added in v0.15.0


Table of contents


3 Functions

asksEither

Effectfully accesses the environment outside of the Reader layer.

Signature

export declare const asksEither: <R, E, A>(f: (r: R) => Either<E, A>) => ReaderEither<R, E, A>
asksEither :: (r -> Either e a) -> ReaderEither r e a

Example

import { asksEither } from 'fp-ts-std/ReaderEither'
import * as E from 'fp-ts/Either'

const lucky = asksEither<number, unknown, boolean>((n) => E.right(n === Date.now()))

assert.deepStrictEqual(lucky(42), E.right(false))

Added in v0.16.0

runReaderEither

Runs a ReaderEither and extracts the final Either from it.

Signature

export declare const runReaderEither: <R, E, A>(r: R) => (reader: ReaderEither<R, E, A>) => Either<E, A>
runReaderEither :: r -> ReaderEither r e a -> Either e a

Example

import { runReaderEither } from 'fp-ts-std/ReaderEither'
import { pipe } from 'fp-ts/function'
import * as RE from 'fp-ts/ReaderEither'
import * as E from 'fp-ts/Either'

type Env = { dependency: string }
const env: Env = { dependency: 'dependency' }

const extractedEither = pipe(E.right(1), RE.fromEither, runReaderEither(env))

assert.deepStrictEqual(extractedEither, E.right(1))

Added in v0.15.0