Skip to main content

State

Instances

Combinators

Constructors

Instance methods

Legacy

Mapping

Model

Sequencing

Traversing

Type lambdas

Utilities

Instances

Applicative

Signature

export declare const Applicative: Applicative2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Apply

Signature

export declare const Apply: Apply2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Chain

Signature

export declare const Chain: chainable.Chain2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

ChainRec

ChainRec for State

Signature

export declare const ChainRec: ChainRec2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2022-present Jacob Alford

FromState

Signature

export declare const FromState: FromState2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Functor

Signature

export declare const Functor: Functor2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Monad

Signature

export declare const Monad: Monad2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Pointed

Signature

export declare const Pointed: Pointed2<URI>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Combinators

tap

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 tap: {
<S, A, _>(self: State<S, A>, f: (a: A) => State<S, _>): State<S, A>
<A, S, _>(f: (a: A) => State<S, _>): (self: State<S, A>) => State<S, A>
}

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Constructors

get

Get the current state

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

gets

Get a value which depends on the current state

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

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>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

of

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

put

Set the state

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Instance methods

chainRec

Signature

export declare const chainRec: ChainRec2<URI>['chainRec']

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2022-present Jacob Alford

Legacy

chain

Alias of flatMap.

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

chainFirst

Alias of tap.

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Mapping

flap

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

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>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Model

State

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Sequencing

flatMap

Signature

export declare const flatMap: {
<A, S, B>(f: (a: A) => State<S, B>): (ma: State<S, A>) => State<S, B>
<S, A, B>(ma: State<S, A>, f: (a: A) => State<S, B>): State<S, B>
}

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

flatten

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Traversing

sequenceArray

Equivalent to ReadonlyArray#sequence(Applicative).

Signature

export declare const sequenceArray: <S, A>(arr: ReadonlyArray<State<S, A>>) => State<S, ReadonlyArray<A>>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseArray

Equivalent to ReadonlyArray#traverse(Applicative).

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(Applicative).

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseReadonlyArrayWithIndex

Equivalent to ReadonlyArray#traverseWithIndex(Applicative).

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

traverseReadonlyNonEmptyArrayWithIndex

Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(Applicative).

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Type lambdas

URI

Signature

export type URI = typeof URI

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

URI

Signature

export declare const URI = 'State'

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

Utilities

ap

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

apFirst

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

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

apS

Signature

export declare const apS: <N extends string, 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 }>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

apSecond

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

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

bind

Signature

export declare const bind: <N extends string, 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 }>

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

bindTo

Signature

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

do

Signature

export declare const do_: <MA extends StateIterable<any, any>, A>(
yieldFunction: (unwrap: <S, A>(ma: State<S, A>) => StateIterable<S, A>) => Generator<MA, A>,
) => State<_.UnionToIntersection<MA extends StateIterable<infer S, any> ? S : never>, A>

evalState

Use evaluate instead

Signature

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

Details

  • Added in 0.1.0
  • Deprecated

License

  • MIT – Copyright (c) 2017-present Giulio Canti

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

execState

Use execute instead

Signature

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

Details

  • Added in 0.1.0
  • Deprecated

License

  • MIT – Copyright (c) 2017-present Giulio Canti

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

Details

  • Added in 0.1.0

License

  • MIT – Copyright (c) 2017-present Giulio Canti

let

Signature

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

state

This instance is deprecated, use small, specific instances instead. For example if a function needs a Functor instance, pass S.Functor instead of S.state (where S is from import S from 'fp-ts/State')

Signature

export declare const state: Monad2<URI>

Details

  • Added in 0.1.0
  • Deprecated

License

  • MIT – Copyright (c) 2017-present Giulio Canti