ReaderTask overview

Utility functions to accommodate fp-ts/ReaderTask.

Added in v0.15.0


Table of contents


3 Functions

asksTask

Effectfully accesses the environment outside of the Reader layer.

Signature

export declare const asksTask: <R, A>(f: (r: R) => Task<A>) => ReaderTask<R, A>
asksTask :: (r -> Task a) -> ReaderTask r a

Example

import { asksTask } from 'fp-ts-std/ReaderTask'

const lucky = asksTask<number, boolean>((n) => () => Promise.resolve(n === Date.now()))

assert.deepEqual(lucky(42)(), Promise.resolve(false))

Added in v0.16.0

runReaderTask

Runs a ReaderTask and extracts the final Task from it.

Signature

export declare const runReaderTask: <R, A>(r: R) => (reader: ReaderTask<R, A>) => Task<A>
runReaderTask :: r -> ReaderTask r a -> Task a

Example

import { runReaderTask } from 'fp-ts-std/ReaderTask'
import { pipe } from 'fp-ts/function'
import * as RT from 'fp-ts/ReaderTask'

type Env = { dependency: string }
const env: Env = { dependency: 'dependency ' }
pipe(RT.of<Env, number>(1), runReaderTask(env))().then((extractedValue) => assert.strictEqual(extractedValue, 1))

Added in v0.15.0