State overview

Added in v2.0.0


Table of contents


Applicative

of

Signature

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

Added in v2.0.0

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>

Added in v2.0.0

apFirst

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

Signature

export declare const apFirst: <E, B>(fb: State<E, B>) => <A>(fa: State<E, A>) => State<E, A>

Added in v2.0.0

apSecond

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

Signature

export declare const apSecond: <E, B>(fb: State<E, B>) => <A>(fa: State<E, A>) => State<E, 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) => <E>(fa: State<E, A>) => State<E, 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: <E, A, B>(f: (a: A) => State<E, B>) => (ma: State<E, A>) => State<E, 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.

Signature

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

Added in v2.0.0

flatten

Signature

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

Added in v2.0.0

constructors

get

Get the current state

Signature

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

Added in v2.0.0

gets

Get a value which depends on the current state

Signature

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

Added in v2.0.0

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>

Added in v2.0.0

put

Set the state

Signature

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

Added in v2.0.0

instances

URI

Signature

export declare const URI: 'State'

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

applicativeState

Signature

export declare const applicativeState: Applicative2<'State'>

Added in v2.7.0

functorState

Signature

export declare const functorState: Functor2<'State'>

Added in v2.7.0

monadState

Signature

export declare const monadState: Monad2<'State'>

Added in v2.7.0

state

Signature

export declare const state: Monad2<'State'>

Added in v2.0.0

model

State (interface)

Signature

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

Added in v2.0.0

utils

evalState

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

Signature

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

Added in v2.0.0

execState

Run a computation in the State monad discarding the result

Signature

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

Added in v2.0.0