TaskOption overview

Added in v2.10.0


Table of contents


combinators

tap

Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

Signature

export declare const tap: {
  <A, _>(self: TaskOption<A>, f: (a: A) => TaskOption<_>): TaskOption<A>
  <A, _>(f: (a: A) => TaskOption<_>): (self: TaskOption<A>) => TaskOption<A>
}

Added in v2.15.0

tapEither

Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

Signature

export declare const tapEither: {
  <A, E, _>(f: (a: A) => Either<E, _>): (self: TaskOption<A>) => TaskOption<A>
  <A, E, _>(self: TaskOption<A>, f: (a: A) => Either<E, _>): TaskOption<A>
}

Example

import { pipe } from 'fp-ts/function'
import * as TO from 'fp-ts/TaskOption'
import * as O from 'fp-ts/Option'
import * as E from 'fp-ts/Either'

const compute = (value: number) =>
  pipe(
    TO.of(value),
    TO.tapEither((value) => (value > 0 ? E.right('ok') : E.left('error')))
  )

async function test() {
  assert.deepStrictEqual(await compute(1)(), O.of(1))
  assert.deepStrictEqual(await compute(-1)(), O.none)
}

test()

Added in v2.16.0

tapIO

Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

Signature

export declare const tapIO: {
  <A, _>(f: (a: A) => IO<_>): (self: TaskOption<A>) => TaskOption<A>
  <A, _>(self: TaskOption<A>, f: (a: A) => IO<_>): TaskOption<A>
}

Example

import { pipe } from 'fp-ts/function'
import * as TO from 'fp-ts/TaskOption'
import * as O from 'fp-ts/Option'
import * as Console from 'fp-ts/Console'

// Will produce `Hello, fp-ts` to the stdout
const effectA = TO.tapIO(TO.of(1), (value) => Console.log(`Hello, ${value}`))

// No output to the stdout
const effectB = pipe(
  TO.none as TO.TaskOption<string>,
  TO.tapIO((value) => Console.log(`Hello, ${value}`))
)

async function test() {
  assert.deepStrictEqual(await effectA(), O.of(1))
  assert.deepStrictEqual(await effectB(), O.none)
}

test()

Added in v2.16.0

tapTask

Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

Signature

export declare const tapTask: {
  <A, _>(f: (a: A) => T.Task<_>): (self: TaskOption<A>) => TaskOption<A>
  <A, _>(self: TaskOption<A>, f: (a: A) => T.Task<_>): TaskOption<A>
}

Example

import * as TO from 'fp-ts/TaskOption'
import * as O from 'fp-ts/Option'
import * as T from 'fp-ts/Task'

const effect = TO.tapIO(TO.of(1), (value) => T.of(value + 1))

async function test() {
  assert.deepStrictEqual(await effect(), O.of(1))
}

test()

Added in v2.16.0

constructors

none

Signature

export declare const none: TaskOption<never>

Added in v2.10.0

of

Signature

export declare const of: <A>(a: A) => TaskOption<A>

Added in v2.10.0

some

Signature

export declare const some: <A>(a: A) => TaskOption<A>

Added in v2.10.0

conversions

fromEither

Signature

export declare const fromEither: <A>(fa: Either<unknown, A>) => TaskOption<A>

Added in v2.10.0

fromIO

Signature

export declare const fromIO: <A>(fa: IO<A>) => TaskOption<A>

Added in v2.10.0

fromNullable

Signature

export declare const fromNullable: <A>(a: A) => TaskOption<NonNullable<A>>

Added in v2.10.0

fromOption

Signature

export declare const fromOption: <A>(fa: O.Option<A>) => TaskOption<A>

Added in v2.10.0

fromTask

Signature

export declare const fromTask: <A>(fa: T.Task<A>) => TaskOption<A>

Added in v2.10.0

fromTaskEither

Signature

export declare const fromTaskEither: <A>(fa: TaskEither<unknown, A>) => TaskOption<A>

Added in v2.11.0

do notation

Do

Signature

export declare const Do: TaskOption<{}>

Added in v2.10.0

apS

Signature

export declare const apS: <N, A, B>(
  name: Exclude<N, keyof A>,
  fb: TaskOption<B>
) => (fa: TaskOption<A>) => TaskOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v2.10.0

bind

Signature

export declare const bind: <N, A, B>(
  name: Exclude<N, keyof A>,
  f: (a: A) => TaskOption<B>
) => (ma: TaskOption<A>) => TaskOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v2.10.0

bindTo

Signature

export declare const bindTo: <N>(name: N) => <A>(fa: TaskOption<A>) => TaskOption<{ readonly [K in N]: A }>

Added in v2.10.0

guard

Signature

export declare const guard: (b: boolean) => TaskOption<void>

Added in v2.11.0

let

Signature

export declare const let: <N, A, B>(
  name: Exclude<N, keyof A>,
  f: (a: A) => B
) => (fa: TaskOption<A>) => TaskOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v2.13.0

error handling

alt

Signature

export declare const alt: <A>(second: LazyArg<TaskOption<A>>) => (first: TaskOption<A>) => TaskOption<A>

Added in v2.10.0

altW

Less strict version of alt.

The W suffix (short for Widening) means that the return types will be merged.

Signature

export declare const altW: <B>(second: LazyArg<TaskOption<B>>) => <A>(first: TaskOption<A>) => TaskOption<B | A>

Added in v2.10.0

getOrElse

Signature

export declare const getOrElse: <A>(onNone: LazyArg<T.Task<A>>) => (fa: TaskOption<A>) => T.Task<A>

Added in v2.10.0

getOrElseW

Less strict version of getOrElse.

The W suffix (short for Widening) means that the handler return type will be merged.

Signature

export declare const getOrElseW: <B>(onNone: LazyArg<T.Task<B>>) => <A>(ma: TaskOption<A>) => T.Task<B | A>

Added in v2.10.0

filtering

compact

Signature

export declare const compact: <A>(fa: TaskOption<O.Option<A>>) => TaskOption<A>

Added in v2.10.0

filter

Signature

export declare const filter: {
  <A, B extends A>(refinement: Refinement<A, B>): (fb: TaskOption<A>) => TaskOption<B>
  <A>(predicate: Predicate<A>): <B extends A>(fb: TaskOption<B>) => TaskOption<B>
  <A>(predicate: Predicate<A>): (fa: TaskOption<A>) => TaskOption<A>
}

Added in v2.10.0

filterMap

Signature

export declare const filterMap: <A, B>(f: (a: A) => O.Option<B>) => (fga: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

partition

Signature

export declare const partition: {
  <A, B extends A>(refinement: Refinement<A, B>): (fb: TaskOption<A>) => Separated<TaskOption<A>, TaskOption<B>>
  <A>(predicate: Predicate<A>): <B extends A>(fb: TaskOption<B>) => Separated<TaskOption<B>, TaskOption<B>>
  <A>(predicate: Predicate<A>): (fa: TaskOption<A>) => Separated<TaskOption<A>, TaskOption<A>>
}

Added in v2.10.0

partitionMap

Signature

export declare const partitionMap: <A, B, C>(
  f: (a: A) => Either<B, C>
) => (fa: TaskOption<A>) => Separated<TaskOption<B>, TaskOption<C>>

Added in v2.10.0

separate

Signature

export declare const separate: <A, B>(fa: TaskOption<Either<A, B>>) => Separated<TaskOption<A>, TaskOption<B>>

Added in v2.10.0

instances

Alt

Signature

export declare const Alt: Alt1<'TaskOption'>

Added in v2.10.0

Alternative

Signature

export declare const Alternative: Alternative1<'TaskOption'>

Added in v2.10.0

ApplicativePar

Runs computations in parallel.

Signature

export declare const ApplicativePar: Applicative1<'TaskOption'>

Added in v2.10.0

ApplicativeSeq

Runs computations sequentially.

Signature

export declare const ApplicativeSeq: Applicative1<'TaskOption'>

Added in v2.10.0

ApplyPar

Runs computations in parallel.

Signature

export declare const ApplyPar: Apply1<'TaskOption'>

Added in v2.10.0

ApplySeq

Runs computations sequentially.

Signature

export declare const ApplySeq: Apply1<'TaskOption'>

Added in v2.10.0

Chain

Signature

export declare const Chain: chainable.Chain1<'TaskOption'>

Added in v2.10.0

Compactable

Signature

export declare const Compactable: Compactable1<'TaskOption'>

Added in v2.10.0

Filterable

Signature

export declare const Filterable: Filterable1<'TaskOption'>

Added in v2.10.0

FromEither

Signature

export declare const FromEither: FromEither1<'TaskOption'>

Added in v2.11.0

FromIO

Signature

export declare const FromIO: FromIO1<'TaskOption'>

Added in v2.10.0

FromTask

Signature

export declare const FromTask: FromTask1<'TaskOption'>

Added in v2.10.0

Functor

Signature

export declare const Functor: Functor1<'TaskOption'>

Added in v2.10.0

Monad

Signature

export declare const Monad: Monad1<'TaskOption'>

Added in v2.10.0

MonadIO

Signature

export declare const MonadIO: MonadIO1<'TaskOption'>

Added in v2.10.0

MonadTask

Signature

export declare const MonadTask: MonadTask1<'TaskOption'>

Added in v2.10.0

Pointed

Signature

export declare const Pointed: Pointed1<'TaskOption'>

Added in v2.10.0

Zero

Signature

export declare const Zero: Zero1<'TaskOption'>

Added in v2.11.0

interop

tryCatch

Transforms a Promise that may reject to a Promise that never rejects and returns an Option instead.

See also tryCatchK.

Signature

export declare const tryCatch: <A>(f: LazyArg<Promise<A>>) => TaskOption<A>

Added in v2.10.0

tryCatchK

Converts a function returning a Promise to one returning a TaskOption.

Signature

export declare const tryCatchK: <A extends readonly unknown[], B>(
  f: (...a: A) => Promise<B>
) => (...a: A) => TaskOption<B>

Added in v2.10.0

legacy

chain

Alias of flatMap.

Signature

export declare const chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

chainFirst

Alias of tap.

Signature

export declare const chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (first: TaskOption<A>) => TaskOption<A>

Added in v2.10.0

chainFirstEitherK

Alias of tapEither.

Signature

export declare const chainFirstEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: TaskOption<A>) => TaskOption<A>

Added in v2.12.0

chainFirstIOK

Alias of tapIO.

Signature

export declare const chainFirstIOK: <A, B>(f: (a: A) => IO<B>) => (first: TaskOption<A>) => TaskOption<A>

Added in v2.10.0

chainFirstTaskK

Alias of tapTask.

Signature

export declare const chainFirstTaskK: <A, B>(f: (a: A) => T.Task<B>) => (first: TaskOption<A>) => TaskOption<A>

Added in v2.10.0

chainIOK

Alias of flatMapIO.

Signature

export declare const chainIOK: <A, B>(f: (a: A) => IO<B>) => (first: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

chainTaskK

Alias of flatMapTask.

Signature

export declare const chainTaskK: <A, B>(f: (a: A) => T.Task<B>) => (first: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

lifting

fromEitherK

Signature

export declare const fromEitherK: <E, A extends readonly unknown[], B>(
  f: (...a: A) => Either<E, B>
) => (...a: A) => TaskOption<B>

Added in v2.12.0

fromIOK

Signature

export declare const fromIOK: <A extends readonly unknown[], B>(f: (...a: A) => IO<B>) => (...a: A) => TaskOption<B>

Added in v2.10.0

fromNullableK

Signature

export declare const fromNullableK: <A extends readonly unknown[], B>(
  f: (...a: A) => B | null | undefined
) => (...a: A) => TaskOption<NonNullable<B>>

Added in v2.10.0

fromOptionK

Signature

export declare const fromOptionK: <A extends readonly unknown[], B>(
  f: (...a: A) => O.Option<B>
) => (...a: A) => TaskOption<B>

Added in v2.10.0

fromPredicate

Signature

export declare const fromPredicate: {
  <A, B extends A>(refinement: Refinement<A, B>): (a: A) => TaskOption<B>
  <A>(predicate: Predicate<A>): <B extends A>(b: B) => TaskOption<B>
  <A>(predicate: Predicate<A>): (a: A) => TaskOption<A>
}

Added in v2.10.0

fromTaskK

Signature

export declare const fromTaskK: <A extends readonly unknown[], B>(
  f: (...a: A) => T.Task<B>
) => (...a: A) => TaskOption<B>

Added in v2.10.0

mapping

as

Maps the Some value of this TaskOption to the specified constant value.

Signature

export declare const as: {
  <A>(a: A): <_>(self: TaskOption<_>) => TaskOption<A>
  <_, A>(self: TaskOption<_>, a: A): TaskOption<A>
}

Added in v2.16.0

asUnit

Maps the Some value of this TaskOption to the void constant value.

Signature

export declare const asUnit: <_>(self: TaskOption<_>) => TaskOption<void>

Added in v2.16.0

flap

Signature

export declare const flap: <A>(a: A) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>

Added in v2.10.0

map

map can be used to turn functions (a: A) => B into functions (fa: F<A>) => F<B> whose argument and return types use the type constructor F to represent some computational context.

Signature

export declare const map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

model

TaskOption (interface)

Signature

export interface TaskOption<A> extends Task<Option<A>> {}

Added in v2.10.0

pattern matching

fold

Alias of matchE.

Signature

export declare const fold: <B, A>(
  onNone: () => T.Task<B>,
  onSome: (a: A) => T.Task<B>
) => (ma: TaskOption<A>) => T.Task<B>

Added in v2.10.0

foldW

Alias of matchEW.

Signature

export declare const foldW: <B, C, A>(
  onNone: () => T.Task<B>,
  onSome: (a: A) => T.Task<C>
) => (ma: TaskOption<A>) => T.Task<B | C>

Added in v2.10.0

match

Signature

export declare const match: <B, A>(onNone: () => B, onSome: (a: A) => B) => (ma: TaskOption<A>) => T.Task<B>

Added in v2.10.0

matchE

The E suffix (short for Effect) means that the handlers return an effect (Task).

Signature

export declare const matchE: <B, A>(
  onNone: () => T.Task<B>,
  onSome: (a: A) => T.Task<B>
) => (ma: TaskOption<A>) => T.Task<B>

Added in v2.10.0

matchEW

Less strict version of matchE.

The W suffix (short for Widening) means that the handler return types will be merged.

Signature

export declare const matchEW: <B, C, A>(
  onNone: () => T.Task<B>,
  onSome: (a: A) => T.Task<C>
) => (ma: TaskOption<A>) => T.Task<B | C>

Added in v2.10.0

matchW

Less strict version of match.

The W suffix (short for Widening) means that the handler return types will be merged.

Signature

export declare const matchW: <B, A, C>(onNone: () => B, onSome: (a: A) => C) => (ma: TaskOption<A>) => T.Task<B | C>

Added in v2.10.0

sequencing

chainEitherK

Signature

export declare const chainEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: TaskOption<A>) => TaskOption<B>

Added in v2.12.0

chainNullableK

Signature

export declare const chainNullableK: <A, B>(
  f: (a: A) => B | null | undefined
) => (ma: TaskOption<A>) => TaskOption<NonNullable<B>>

Added in v2.10.0

chainOptionK

Signature

export declare const chainOptionK: <A, B>(f: (a: A) => O.Option<B>) => (ma: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

flatMap

Signature

export declare const flatMap: {
  <A, B>(f: (a: A) => TaskOption<B>): (ma: TaskOption<A>) => TaskOption<B>
  <A, B>(ma: TaskOption<A>, f: (a: A) => TaskOption<B>): TaskOption<B>
}

Added in v2.14.0

flatMapIO

Signature

export declare const flatMapIO: {
  <A, B>(f: (a: A) => IO<B>): (self: TaskOption<A>) => TaskOption<B>
  <A, B>(self: TaskOption<A>, f: (a: A) => IO<B>): TaskOption<B>
}

Added in v2.16.0

flatMapTask

Signature

export declare const flatMapTask: {
  <A, B>(f: (a: A) => T.Task<B>): (self: TaskOption<A>) => TaskOption<B>
  <A, B>(self: TaskOption<A>, f: (a: A) => T.Task<B>): TaskOption<B>
}

Added in v2.16.0

flatten

Signature

export declare const flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>

Added in v2.10.0

traversing

sequenceArray

Equivalent to ReadonlyArray#sequence(Applicative).

Signature

export declare const sequenceArray: <A>(as: readonly TaskOption<A>[]) => TaskOption<readonly A[]>

Added in v2.10.0

sequenceSeqArray

Equivalent to ReadonlyArray#sequence(ApplicativeSeq).

Signature

export declare const sequenceSeqArray: <A>(as: readonly TaskOption<A>[]) => TaskOption<readonly A[]>

Added in v2.10.0

traverseArray

Equivalent to ReadonlyArray#traverse(Applicative).

Signature

export declare const traverseArray: <A, B>(f: (a: A) => TaskOption<B>) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.10.0

traverseArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(Applicative).

Signature

export declare const traverseArrayWithIndex: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.10.0

traverseReadonlyArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(ApplicativePar).

Signature

export declare const traverseReadonlyArrayWithIndex: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.11.0

traverseReadonlyArrayWithIndexSeq

Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq).

Signature

export declare const traverseReadonlyArrayWithIndexSeq: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.11.0

traverseReadonlyNonEmptyArrayWithIndex

Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar).

Signature

export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: ReadonlyNonEmptyArray<A>) => TaskOption<ReadonlyNonEmptyArray<B>>

Added in v2.11.0

traverseReadonlyNonEmptyArrayWithIndexSeq

Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(ApplicativeSeq).

Signature

export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: ReadonlyNonEmptyArray<A>) => TaskOption<ReadonlyNonEmptyArray<B>>

Added in v2.11.0

traverseSeqArray

Equivalent to ReadonlyArray#traverse(ApplicativeSeq).

Signature

export declare const traverseSeqArray: <A, B>(
  f: (a: A) => TaskOption<B>
) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.10.0

traverseSeqArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq).

Signature

export declare const traverseSeqArrayWithIndex: <A, B>(
  f: (index: number, a: A) => TaskOption<B>
) => (as: readonly A[]) => TaskOption<readonly B[]>

Added in v2.10.0

type lambdas

URI

Signature

export declare const URI: 'TaskOption'

Added in v2.10.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.10.0

utils

ApT

Signature

export declare const ApT: TaskOption<readonly []>

Added in v2.11.0

ap

Signature

export declare const ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>

Added in v2.10.0

apFirst

Combine two effectful actions, keeping only the result of the first.

Signature

export declare const apFirst: <B>(second: TaskOption<B>) => <A>(first: TaskOption<A>) => TaskOption<A>

Added in v2.10.0

apSecond

Combine two effectful actions, keeping only the result of the second.

Signature

export declare const apSecond: <B>(second: TaskOption<B>) => <A>(first: TaskOption<A>) => TaskOption<B>

Added in v2.10.0

zero

Signature

export declare const zero: <A>() => TaskOption<A>

Added in v2.10.0