Link Search Menu Expand Document

IO overview

interface IO<A> {
  (): A
}

IO<A> represents a non-deterministic synchronous computation that can cause side effects, yields a value of type A and never fails. If you want to represent a synchronous computation that may fail, please see IOEither.

Added in v2.0.0


Table of contents


Apply

ap

Apply a function to an argument under a type constructor.

Signature

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

Added in v2.0.0

Functor

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: IO<A>) => IO<B>

Added in v2.0.0

Monad

chain

Composes computations in sequence, using the return value of one computation to determine the next computation.

Signature

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

Added in v2.0.0

Pointed

of

Signature

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

Added in v2.0.0

combinators

apFirst

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

Derivable from Apply.

Signature

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

Added in v2.0.0

apSecond

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

Derivable from Apply.

Signature

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

Added in v2.0.0

chainFirst

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

Derivable from Chain.

Signature

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

Added in v2.0.0

flap

Derivable from Functor.

Signature

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

Added in v2.10.0

flatten

Derivable from Chain.

Signature

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

Added in v2.0.0

constructors

fromIO

Signature

export declare const fromIO: NaturalTransformation11<'IO', 'IO'>

Added in v2.7.0

instances

Applicative

Signature

export declare const Applicative: Applicative1<'IO'>

Added in v2.7.0

Apply

Signature

export declare const Apply: Apply1<'IO'>

Added in v2.10.0

Chain

Signature

export declare const Chain: Chain1<'IO'>

Added in v2.10.0

ChainRec

Signature

export declare const ChainRec: ChainRec1<'IO'>

Added in v2.7.0

FromIO

Signature

export declare const FromIO: FromIO1<'IO'>

Added in v2.10.0

Functor

Signature

export declare const Functor: Functor1<'IO'>

Added in v2.7.0

Monad

Signature

export declare const Monad: Monad1<'IO'>

Added in v2.7.0

MonadIO

Signature

export declare const MonadIO: MonadIO1<'IO'>

Added in v2.7.0

Pointed

Signature

export declare const Pointed: Pointed1<'IO'>

Added in v2.10.0

URI

Signature

export declare const URI: 'IO'

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

getMonoid

Use getApplicativeMonoid instead.

Signature

export declare const getMonoid: <A>(M: Monoid<A>) => Monoid<IO<A>>

Added in v2.0.0

getSemigroup

Use getApplySemigroup instead.

Signature

export declare const getSemigroup: <A>(S: Semigroup<A>) => Semigroup<IO<A>>

Added in v2.0.0

io

Use small, specific instances instead.

Signature

export declare const io: Monad1<'IO'> & MonadIO1<'IO'> & ChainRec1<'IO'>

Added in v2.0.0

model

IO (interface)

Signature

export interface IO<A> {
  (): A
}

Added in v2.0.0

utils

ApT

Signature

export declare const ApT: IO<readonly []>

Added in v2.11.0

Do

Signature

export declare const Do: IO<{}>

Added in v2.9.0

apS

Signature

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

Added in v2.8.0

bind

Signature

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

Added in v2.8.0

bindTo

Signature

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

Added in v2.8.0

sequenceArray

Signature

export declare const sequenceArray: <A>(arr: readonly IO<A>[]) => IO<readonly A[]>

Added in v2.9.0

traverseArray

Signature

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

Added in v2.9.0

traverseArrayWithIndex

Signature

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

Added in v2.9.0

traverseReadonlyArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(Applicative).

Signature

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

Added in v2.11.0

traverseReadonlyNonEmptyArrayWithIndex

Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(Applicative).

Signature

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

Added in v2.11.0