UNPKG

fp-ts

Version:

Functional programming in TypeScript

312 lines (311 loc) 7.9 kB
/** * ```ts * 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`. * If you want to represent a synchronous computation that may yield nothing, please see `IOOption`. * * @since 2.0.0 */ import { Applicative1 } from './Applicative' import { Apply1 } from './Apply' import * as chainable from './Chain' import { ChainRec1 } from './ChainRec' import { FromIO1 } from './FromIO' import { Functor1 } from './Functor' import { Monad1 } from './Monad' import { MonadIO1 } from './MonadIO' import { Monoid } from './Monoid' import { Pointed1 } from './Pointed' import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray' import { Semigroup } from './Semigroup' /** * @category model * @since 2.0.0 */ export interface IO<A> { (): A } /** * `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. * * @category mapping * @since 2.0.0 */ export declare const map: <A, B>(f: (a: A) => B) => (fa: IO<A>) => IO<B> /** * @since 2.0.0 */ export declare const ap: <A>(fa: IO<A>) => <B>(fab: IO<(a: A) => B>) => IO<B> /** * @category constructors * @since 2.0.0 */ export declare const of: <A>(a: A) => IO<A> /** * @category sequencing * @since 2.14.0 */ export declare const flatMap: { <A, B>(f: (a: A) => IO<B>): (ma: IO<A>) => IO<B> <A, B>(ma: IO<A>, f: (a: A) => IO<B>): IO<B> } /** * @category sequencing * @since 2.0.0 */ export declare const flatten: <A>(mma: IO<IO<A>>) => IO<A> /** * @category type lambdas * @since 2.0.0 */ export declare const URI = 'IO' /** * @category type lambdas * @since 2.0.0 */ export type URI = typeof URI declare module './HKT' { interface URItoKind<A> { readonly [URI]: IO<A> } } /** * @category instances * @since 2.7.0 */ export declare const Functor: Functor1<URI> /** * Maps the value to the specified constant value. * * @category mapping * @since 2.16.0 */ export declare const as: { <A>(a: A): <_>(self: IO<_>) => IO<A> <_, A>(self: IO<_>, a: A): IO<A> } /** * Maps the value to the void constant value. * * @category mapping * @since 2.16.0 */ export declare const asUnit: <_>(self: IO<_>) => IO<void> /** * @category mapping * @since 2.10.0 */ export declare const flap: <A>( a: A ) => <B>(fab: import('./HKT').Kind<'IO', (a: A) => B>) => import('./HKT').Kind<'IO', B> /** * @category instances * @since 2.10.0 */ export declare const Pointed: Pointed1<URI> /** * @category instances * @since 2.10.0 */ export declare const Apply: Apply1<URI> /** * Combine two effectful actions, keeping only the result of the first. * * @since 2.0.0 */ export declare const apFirst: <B>( second: IO<B> ) => <A>(first: import('./HKT').Kind<'IO', A>) => import('./HKT').Kind<'IO', A> /** * Combine two effectful actions, keeping only the result of the second. * * @since 2.0.0 */ export declare const apSecond: <B>( second: IO<B> ) => <A>(first: import('./HKT').Kind<'IO', A>) => import('./HKT').Kind<'IO', B> /** * @category instances * @since 2.7.0 */ export declare const Applicative: Applicative1<URI> /** * @category instances * @since 2.10.0 */ export declare const Chain: chainable.Chain1<URI> /** * @category instances * @since 2.7.0 */ export declare const Monad: Monad1<URI> /** * Composes computations in sequence, using the return value of one computation to determine the next computation and * keeping only the result of the first. * * @category combinators * @since 2.15.0 */ export declare const tap: { <A, _>(self: IO<A>, f: (a: A) => IO<_>): IO<A> <A, _>(f: (a: A) => IO<_>): (self: IO<A>) => IO<A> } /** * @category zone of death * @since 2.7.0 * @deprecated */ export declare const fromIO: <A>(fa: IO<A>) => IO<A> /** * @category instances * @since 2.7.0 */ export declare const MonadIO: MonadIO1<URI> /** * @category instances * @since 2.7.0 */ export declare const ChainRec: ChainRec1<URI> /** * @category instances * @since 2.10.0 */ export declare const FromIO: FromIO1<URI> /** * @category do notation * @since 2.9.0 */ export declare const Do: IO<{}> /** * @category do notation * @since 2.8.0 */ export declare const bindTo: <N extends string>( name: N ) => <A>(fa: import('./HKT').Kind<'IO', A>) => import('./HKT').Kind<'IO', { readonly [K in N]: A }> declare const let_: <N extends string, A, B>( name: Exclude<N, keyof A>, f: (a: A) => B ) => ( fa: import('./HKT').Kind<'IO', A> ) => import('./HKT').Kind<'IO', { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> export { /** * @category do notation * @since 2.13.0 */ let_ as let } /** * @category do notation * @since 2.8.0 */ export declare const bind: <N extends string, A, B>( name: Exclude<N, keyof A>, f: (a: A) => import('./HKT').Kind<'IO', B> ) => ( ma: import('./HKT').Kind<'IO', A> ) => import('./HKT').Kind<'IO', { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> /** * @category do notation * @since 2.8.0 */ export declare const apS: <N extends string, A, B>( name: Exclude<N, keyof A>, fb: IO<B> ) => ( fa: import('./HKT').Kind<'IO', A> ) => import('./HKT').Kind<'IO', { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> /** * @since 2.11.0 */ export declare const ApT: IO<readonly []> /** * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, B>( f: (index: number, a: A) => IO<B> ) => (as: ReadonlyNonEmptyArray<A>) => IO<ReadonlyNonEmptyArray<B>> /** * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.11.0 */ export declare const traverseReadonlyArrayWithIndex: <A, B>( f: (index: number, a: A) => IO<B> ) => (as: ReadonlyArray<A>) => IO<ReadonlyArray<B>> /** * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const traverseArrayWithIndex: <A, B>( f: (index: number, a: A) => IO<B> ) => (as: ReadonlyArray<A>) => IO<ReadonlyArray<B>> /** * Equivalent to `ReadonlyArray#traverse(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const traverseArray: <A, B>(f: (a: A) => IO<B>) => (as: ReadonlyArray<A>) => IO<ReadonlyArray<B>> /** * Equivalent to `ReadonlyArray#sequence(Applicative)`. * * @category traversing * @since 2.9.0 */ export declare const sequenceArray: <A>(arr: ReadonlyArray<IO<A>>) => IO<ReadonlyArray<A>> /** * Alias of `flatMap`. * * @category legacy * @since 2.0.0 */ export declare const chain: <A, B>(f: (a: A) => IO<B>) => (ma: IO<A>) => IO<B> /** * Alias of `tap`. * * @category legacy * @since 2.0.0 */ export declare const chainFirst: <A, B>(f: (a: A) => IO<B>) => (first: IO<A>) => IO<A> /** * This instance is deprecated, use small, specific instances instead. * For example if a function needs a `Functor` instance, pass `IO.Functor` instead of `IO.io` * (where `IO` is from `import IO from 'fp-ts/IO'`) * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const io: Monad1<URI> & MonadIO1<URI> & ChainRec1<URI> /** * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getSemigroup: <A>(S: Semigroup<A>) => Semigroup<IO<A>> /** * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getMonoid: <A>(M: Monoid<A>) => Monoid<IO<A>>