# Apply

## ap

Apply a function to an argument under a type constructor.

Signature

``````export declare const ap: <E, A>(fa: State<E, A>) => <B>(fab: State<E, (a: A) => B>) => State<E, B>
``````

# 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) => <E>(fa: State<E, A>) => State<E, B>
``````

## chain

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

Signature

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

# Pointed

## of

Signature

``````export declare const of: <E, A>(a: A) => State<E, A>
``````

# combinators

## apFirst

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

Derivable from `Apply`.

Signature

``````export declare const apFirst: <E, B>(second: State<E, B>) => <A>(first: State<E, A>) => State<E, A>
``````

## apSecond

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

Derivable from `Apply`.

Signature

``````export declare const apSecond: <E, B>(second: State<E, B>) => <A>(first: State<E, A>) => State<E, B>
``````

## 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: <S, A, B>(f: (a: A) => State<S, B>) => (ma: State<S, A>) => State<S, A>
``````

## flap

Derivable from `Functor`.

Signature

``````export declare const flap: <A>(a: A) => <E, B>(fab: State<E, (a: A) => B>) => State<E, B>
``````

## flatten

Derivable from `Chain`.

Signature

``````export declare const flatten: <E, A>(mma: State<E, State<E, A>>) => State<E, A>
``````

# constructors

## get

Get the current state

Signature

``````export declare const get: <S>() => State<S, S>
``````

## gets

Get a value which depends on the current state

Signature

``````export declare const gets: <S, A>(f: (s: S) => A) => State<S, A>
``````

## modify

Modify the state by applying a function to the current state

Signature

``````export declare const modify: <S>(f: (s: S) => S) => State<S, void>
``````

## put

Set the state

Signature

``````export declare const put: <S>(s: S) => State<S, void>
``````

# instances

## Applicative

Signature

``````export declare const Applicative: Applicative2<'State'>
``````

## Apply

Signature

``````export declare const Apply: Apply2<'State'>
``````

## Chain

Signature

``````export declare const Chain: Chain2<'State'>
``````

## FromState

Signature

``````export declare const FromState: FromState2<'State'>
``````

## Functor

Signature

``````export declare const Functor: Functor2<'State'>
``````

Signature

``````export declare const Monad: Monad2<'State'>
``````

## Pointed

Signature

``````export declare const Pointed: Pointed2<'State'>
``````

## URI

Signature

``````export declare const URI: 'State'
``````

## URI (type alias)

Signature

``````export type URI = typeof URI
``````

## state

Signature

``````export declare const state: Monad2<'State'>
``````

# model

## State (interface)

Signature

``````export interface State<S, A> {
(s: S): [A, S]
}
``````

# utils

## apS

Signature

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

## bind

Signature

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

## bindTo

Signature

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

## evaluate

Run a computation in the `State` monad, discarding the final state

Signature

``````export declare const evaluate: <S>(s: S) => <A>(ma: State<S, A>) => A
``````

## execute

Run a computation in the `State` monad discarding the result

Signature

``````export declare const execute: <S>(s: S) => <A>(ma: State<S, A>) => S
``````

## sequenceArray

Signature

``````export declare const sequenceArray: <S, A>(arr: readonly State<S, A>[]) => State<S, readonly A[]>
``````

## traverseArray

Signature

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

## traverseArrayWithIndex

Signature

``````export declare const traverseArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>
``````

Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.

Signature

``````export declare const traverseReadonlyArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>
``````

Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.

Signature

``````export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>
``````

## evalState

Use `evaluate` instead

Signature

``````export declare const evalState: <S, A>(ma: State<S, A>, s: S) => A
``````

Use `execute` instead
``````export declare const execState: <S, A>(ma: State<S, A>, s: S) => S