import { Functor2 } from './Functor' import { Monad2 } from './Monad' import { Applicative2 } from './Applicative' /** * @category model * @since 2.0.0 */ export interface State { (s: S): [A, S] } /** * Get the current state * * @category constructors * @since 2.0.0 */ export declare const get: () => State /** * Set the state * * @category constructors * @since 2.0.0 */ export declare const put: (s: S) => State /** * Modify the state by applying a function to the current state * * @category constructors * @since 2.0.0 */ export declare const modify: (f: (s: S) => S) => State /** * Get a value which depends on the current state * * @category constructors * @since 2.0.0 */ export declare const gets: (f: (s: S) => A) => State /** * `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: State) => State /** * Apply a function to an argument under a type constructor. * * @category Apply * @since 2.0.0 */ export declare const ap: (fa: State) => (fab: State B>) => State /** * 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: State) => (fa: State) => State /** * 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: State) => (fa: State) => State /** * Wrap a value into the type constructor. * * @category Applicative * @since 2.0.0 */ export declare const of: Applicative2['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) => State) => (ma: State) => State /** * 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) => State) => (ma: State) => State /** * Derivable from `Monad`. * * @category combinators * @since 2.0.0 */ export declare const flatten: (mma: State>) => State /** * @category instances * @since 2.0.0 */ export declare const URI = 'State' /** * @category instances * @since 2.0.0 */ export declare type URI = typeof URI declare module './HKT' { interface URItoKind2 { readonly [URI]: State } } /** * @category instances * @since 2.7.0 */ export declare const Functor: Functor2 /** * @category instances * @since 2.7.0 */ export declare const Applicative: Applicative2 /** * @category instances * @since 2.7.0 */ export declare const Monad: Monad2 /** * @category instances * @since 2.0.0 */ export declare const state: Monad2 /** * Use `evaluate` instead * * @since 2.0.0 * @deprecated */ export declare const evalState: (ma: State, s: S) => A /** * Use `execute` instead * * @since 2.0.0 * @deprecated */ export declare const execState: (ma: State, s: S) => S /** * Run a computation in the `State` monad, discarding the final state * * @since 2.8.0 */ export declare const evaluate: (s: S) => (ma: State) => A /** * Run a computation in the `State` monad discarding the result * * @since 2.8.0 */ export declare const execute: (s: S) => (ma: State) => S /** * @since 2.8.0 */ export declare const bindTo: (name: N) => (fa: State) => State /** * @since 2.8.0 */ export declare const bind: ( name: Exclude, f: (a: A) => State ) => (fa: State) => State /** * @since 2.8.0 */ export declare const apS: ( name: Exclude, fb: State ) => (fa: State) => State /** * @since 2.9.0 */ export declare const traverseArrayWithIndex: ( f: (index: number, a: A) => State ) => (arr: ReadonlyArray) => State> /** * This function has the same behavior of `A.traverse(S.State)` but it's stack safe and optimized * * @example * import * as RA from 'fp-ts/ReadonlyArray' * import { traverseArray, State } from 'fp-ts/State' * import { pipe, tuple } from 'fp-ts/function' * * const add = (n: number): State => (s: number) => tuple(n, n + s) * const arr = RA.range(0, 100) * * assert.deepStrictEqual(pipe(arr, traverseArray(add))(0), [arr, arr.reduce((p, c) => p + c, 0)]) * * @since 2.9.0 */ export declare const traverseArray: ( f: (a: A) => State ) => (arr: ReadonlyArray) => State> /** * This function has the same behavior of `A.sequence(S.State)` but it's stack safe and optimized * * @example * import * as RA from 'fp-ts/ReadonlyArray' * import { sequenceArray, State } from 'fp-ts/State' * import { pipe, tuple } from 'fp-ts/function' * * const add = (n: number): State => (s: number) => tuple(n, n + s) * const arr = RA.range(0, 100) * * assert.deepStrictEqual(pipe(arr, RA.map(add), sequenceArray)(0), [arr, arr.reduce((p, c) => p + c, 0)]) * * @since 2.9.0 */ export declare const sequenceArray: (arr: ReadonlyArray>) => State>