/** * ```ts * interface IO { * (): A * } * ``` * * `IO` 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`. * * @since 2.0.0 */ import { Applicative1 } from './Applicative' import { ChainRec1 } from './ChainRec' import { Functor1 } from './Functor' import { Monad1 } from './Monad' import { MonadIO1 } from './MonadIO' import { Monoid } from './Monoid' import { Semigroup } from './Semigroup' /** * @category model * @since 2.0.0 */ export interface IO { (): A } /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types * use the type constructor `F` to represent some computational context. * * @category Functor * @since 2.0.0 */ export declare const map: (f: (a: A) => B) => (fa: IO) => IO /** * Apply a function to an argument under a type constructor. * * @category Apply * @since 2.0.0 */ export declare const ap: (fa: IO) => (fab: IO<(a: A) => B>) => IO /** * Combine two effectful actions, keeping only the result of the first. * * Derivable from `Apply`. * * @category combinators * @since 2.0.0 */ export declare const apFirst: (fb: IO) => (fa: IO) => IO /** * Combine two effectful actions, keeping only the result of the second. * * Derivable from `Apply`. * * @category combinators * @since 2.0.0 */ export declare const apSecond: (fb: IO) => (fa: IO) => IO /** * Wrap a value into the type constructor. * * @category Applicative * @since 2.0.0 */ export declare const of: Applicative1['of'] /** * Composes computations in sequence, using the return value of one computation to determine the next computation. * * @category Monad * @since 2.0.0 */ export declare const chain: (f: (a: A) => IO) => (ma: IO) => IO /** * 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 `Monad`. * * @category combinators * @since 2.0.0 */ export declare const chainFirst: (f: (a: A) => IO) => (ma: IO) => IO /** * Derivable from `Monad`. * * @category combinators * @since 2.0.0 */ export declare const flatten: (mma: IO>) => IO /** * @category MonadIO * @since 2.7.0 */ export declare const fromIO: MonadIO1['fromIO'] /** * @category instances * @since 2.0.0 */ export declare const URI = 'IO' /** * @category instances * @since 2.0.0 */ export declare type URI = typeof URI declare module './HKT' { interface URItoKind { readonly [URI]: IO } } /** * @category instances * @since 2.0.0 */ export declare function getSemigroup(S: Semigroup): Semigroup> /** * @category instances * @since 2.0.0 */ export declare function getMonoid(M: Monoid): Monoid> /** * @category instances * @since 2.7.0 */ export declare const Functor: Functor1 /** * @category instances * @since 2.7.0 */ export declare const Applicative: Applicative1 /** * @category instances * @since 2.7.0 */ export declare const Monad: Monad1 /** * @category instances * @since 2.7.0 */ export declare const MonadIO: MonadIO1 /** * @category instances * @since 2.7.0 */ export declare const ChainRec: ChainRec1 /** * @category instances * @since 2.0.0 */ export declare const io: Monad1 & MonadIO1 & ChainRec1 /** * @since 2.9.0 */ export declare const Do: IO<{}> /** * @since 2.8.0 */ export declare const bindTo: (name: N) => (fa: IO) => IO<{ [K in N]: A }> /** * @since 2.8.0 */ export declare const bind: ( name: Exclude, f: (a: A) => IO ) => (fa: IO) => IO<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * @since 2.8.0 */ export declare const apS: ( name: Exclude, fb: IO ) => (fa: IO) => IO<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * @since 2.9.0 */ export declare const traverseArrayWithIndex: ( f: (index: number, a: A) => IO ) => (arr: ReadonlyArray) => IO> /** * runs an action for every element in array, and accumulates the results IO in the array. * * this function have the same behavior of `A.traverse(IO.io)` but it's stack safe * * @example * import * as RA from 'fp-ts/ReadonlyArray' * import { traverseArray, IO } from 'fp-ts/IO' * import { pipe } from 'fp-ts/function' * * const logger: Array = [] * const log: (a: A) => IO = (a) => () => { logger.push(a) } * * pipe(RA.range(0, 100), traverseArray(log))() * assert.deepStrictEqual(logger, RA.range(0, 100)) * * @since 2.9.0 */ export declare const traverseArray: (f: (a: A) => IO) => (arr: ReadonlyArray) => IO> /** * transform Array of IO to IO of Array * * this function have the same behavior of `A.sequence(IO.io)` but it's stack safe * * @example * import * as RA from 'fp-ts/ReadonlyArray' * import { sequenceArray, IO } from 'fp-ts/IO' * import { pipe } from 'fp-ts/function' * * const logger: Array = [] * const log: (a: A) => IO = (a) => () => { logger.push(a) } * * pipe(RA.range(0, 100), RA.map(log), sequenceArray)() * assert.deepStrictEqual(logger, RA.range(0, 100)) * * @since 2.9.0 */ export declare const sequenceArray: (arr: ReadonlyArray>) => IO>