- sequenceArray
- traverseArray
- traverseArrayWithIndex
- traverseReadonlyArrayWithIndex
- traverseReadonlyNonEmptyArrayWithIndex
- ap
- apFirst
- apS
- apSecond
- bind
- bindTo
- do
evalState(deprecated)- evaluate
execState(deprecated)- execute
- let
state(deprecated)
export declare const Applicative: Applicative2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Apply: Apply2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Chain: chainable.Chain2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
ChainRec for State
export declare const ChainRec: ChainRec2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2022-present Jacob Alford
export declare const FromState: FromState2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Functor: Functor2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Monad: Monad2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Pointed: Pointed2<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
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>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Get the current state
export declare const get: <S>() => State<S, S>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Get a value which depends on the current state
export declare const gets: <S, A>(f: (s: S) => A) => State<S, A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Modify the state by applying a function to the current state
export declare const modify: <S>(f: (s: S) => S) => State<S, void>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const of: <S, A>(a: A) => State<S, A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Set the state
export declare const put: <S>(s: S) => State<S, void>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const chainRec: ChainRec2<URI>['chainRec']
- Added in 0.1.0
- MIT – Copyright (c) 2022-present Jacob Alford
Alias of flatMap
.
export declare const chain: <S, A, B>(f: (a: A) => State<S, B>) => (ma: State<S, A>) => State<S, B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of tap
.
export declare const chainFirst: <S, A, B>(f: (a: A) => State<S, B>) => (ma: State<S, A>) => State<S, A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const flap: <A>(a: A) => <E, B>(fab: State<E, (a: A) => B>) => State<E, B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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.
export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: State<E, A>) => State<E, B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export interface State<S, A> {
(s: S): [A, S]
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const flatten: <E, A>(mma: State<E, State<E, A>>) => State<E, A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#sequence(Applicative)
.
export declare const sequenceArray: <S, A>(arr: ReadonlyArray<State<S, A>>) => State<S, ReadonlyArray<A>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverse(Applicative)
.
export declare const traverseArray: <A, S, B>(f: (a: A) => State<S, B>) => (as: readonly A[]) => State<S, readonly B[]>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverseWithIndex(Applicative)
.
export declare const traverseArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>,
) => (as: ReadonlyArray<A>) => State<S, ReadonlyArray<B>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverseWithIndex(Applicative)
.
export declare const traverseReadonlyArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>,
) => (as: readonly A[]) => State<S, readonly B[]>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(Applicative)
.
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, S, B>(
f: (index: number, a: A) => State<S, B>,
) => (as: ReadonlyNonEmptyArray<A>) => State<S, ReadonlyNonEmptyArray<B>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export type URI = typeof URI
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const URI = 'State'
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const ap: <E, A>(fa: State<E, A>) => <B>(fab: State<E, (a: A) => B>) => State<E, B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Combine two effectful actions, keeping only the result of the first.
export declare const apFirst: <E, B>(second: State<E, B>) => <A>(first: State<E, A>) => State<E, A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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 }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Combine two effectful actions, keeping only the result of the second.
export declare const apSecond: <E, B>(second: State<E, B>) => <A>(first: State<E, A>) => State<E, B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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 }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const bindTo: <N extends string>(
name: N,
) => <E, A>(fa: State<E, A>) => State<E, { readonly [K in N]: A }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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>
Use evaluate
instead
export declare const evalState: <S, A>(ma: State<S, A>, s: S) => A
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
Run a computation in the State
monad, discarding the final state
export declare const evaluate: <S>(s: S) => <A>(ma: State<S, A>) => A
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Use execute
instead
export declare const execState: <S, A>(ma: State<S, A>, s: S) => S
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
Run a computation in the State
monad discarding the result
export declare const execute: <S>(s: S) => <A>(ma: State<S, A>) => S
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
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 }>
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'
)
export declare const state: Monad2<URI>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti