TaskOption overview

Utility functions to accommodate fp-ts/TaskOption.

Added in v0.15.0


Table of contents


2 Typeclass Methods

pass

Convenient alias for TO.of(undefined).

Signature

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

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

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

Added in v0.17.0

3 Functions

unsafeExpect

Unwrap the promise from within a TaskOption, rejecting with msg if None.

Signature

export declare const unsafeExpect: (msg: string) => <A>(x: TaskOption<A>) => Promise<A>
unsafeExpect :: string -> TaskOption a -> Promise a

Example

import { unsafeExpect } from 'fp-ts-std/TaskOption'
import * as TO from 'fp-ts/TaskOption'

assert.rejects(unsafeExpect('foo')(TO.none), Error('Unwrapped `None`'))

Added in v0.16.0

unsafeUnwrap

Unwrap the promise from within a TaskOption, rejecting if None.

Signature

export declare const unsafeUnwrap: <A>(x: TaskOption<A>) => Promise<A>
unsafeUnwrap :: TaskOption a -> Promise a

Example

import { unsafeUnwrap } from 'fp-ts-std/TaskOption'
import * as TO from 'fp-ts/TaskOption'

unsafeUnwrap(TO.of(5)).then((x) => {
  assert.strictEqual(x, 5)
})

Added in v0.15.0