Documentation
¶
Index ¶
- func Applicative[S, A, B any]() applicative.Applicative[A, B, State[S, A], State[S, B], State[S, func(A) B]]
- func Eq[S, A any](w eq.Eq[S], a eq.Eq[A]) func(S) eq.Eq[State[S, A]]
- func Evaluate[A, S any](s S) func(State[S, A]) A
- func Execute[A, S any](s S) func(State[S, A]) S
- func FromStrictEquals[S, A comparable]() func(S) eq.Eq[State[S, A]]
- func Functor[S, A, B any]() functor.Functor[A, B, State[S, A], State[S, B]]
- func Monad[S, A, B any]() monad.Monad[A, B, State[S, A], State[S, B], State[S, func(A) B]]
- func Pointed[S, A any]() pointed.Pointed[A, State[S, A]]
- type Endomorphism
- func ApSL[ST, S, T any](lens Lens[S, T], fa State[ST, T]) Endomorphism[State[ST, S]]
- func BindL[ST, S, T any](lens Lens[S, T], f Kleisli[ST, T, T]) Endomorphism[State[ST, S]]
- func LetL[ST, S, T any](lens Lens[S, T], f Endomorphism[T]) Endomorphism[State[ST, S]]
- func LetToL[ST, S, T any](lens Lens[S, T], b T) Endomorphism[State[ST, S]]
- type Kleisli
- type Lens
- type Operator
- func Ap[B, S, A any](ga State[S, A]) Operator[S, func(A) B, B]
- func ApS[ST, S1, S2, T any](setter func(T) func(S1) S2, fa State[ST, T]) Operator[ST, S1, S2]
- func Bind[ST, S1, S2, T any](setter func(T) func(S1) S2, f Kleisli[ST, S1, T]) Operator[ST, S1, S2]
- func BindTo[ST, S1, T any](setter func(T) S1) Operator[ST, T, S1]
- func Chain[S any, FCT ~func(A) State[S, B], A, B any](f FCT) Operator[S, A, B]
- func ChainFirst[S any, FCT ~func(A) State[S, B], A, B any](f FCT) Operator[S, A, A]
- func Flap[S, A, B any](a A) Operator[S, func(A) B, B]
- func Let[ST, S1, S2, T any](key func(T) func(S1) S2, f func(S1) T) Operator[ST, S1, S2]
- func LetTo[ST, S1, S2, T any](key func(T) func(S1) S2, b T) Operator[ST, S1, S2]
- func Map[S any, FCT ~func(A) B, A, B any](f FCT) Operator[S, A, B]
- type Pair
- type Reader
- type State
- func Do[ST, A any](empty A) State[ST, A]
- func Flatten[S, A any](mma State[S, State[S, A]]) State[S, A]
- func Get[S any]() State[S, S]
- func Gets[FCT ~func(S) A, A, S any](f FCT) State[S, A]
- func Modify[FCT ~func(S) S, S any](f FCT) State[S, any]
- func MonadAp[B, S, A any](fab State[S, func(A) B], fa State[S, A]) State[S, B]
- func MonadChain[S any, FCT ~func(A) State[S, B], A, B any](fa State[S, A], f FCT) State[S, B]
- func MonadChainFirst[S any, FCT ~func(A) State[S, B], A, B any](ma State[S, A], f FCT) State[S, A]
- func MonadFlap[FAB ~func(A) B, S, A, B any](fab State[S, FAB], a A) State[S, B]
- func MonadMap[S any, FCT ~func(A) B, A, B any](fa State[S, A], f FCT) State[S, B]
- func Of[S, A any](a A) State[S, A]
- func Put[S any]() State[S, any]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Applicative ¶
func Applicative[S, A, B any]() applicative.Applicative[A, B, State[S, A], State[S, B], State[S, func(A) B]]
Applicative implements the applicative operations for State
func FromStrictEquals ¶
func FromStrictEquals[S, A comparable]() func(S) eq.Eq[State[S, A]]
FromStrictEquals constructs an eq.Eq from the canonical comparison function
Types ¶
type Endomorphism ¶
type Endomorphism[A any] = endomorphism.Endomorphism[A]
Endomorphism represents a function from a type to itself (A -> A). It's an alias for endomorphism.Endomorphism[A] and is commonly used for state transformations and updates.
func ApSL ¶
func ApSL[ST, S, T any]( lens Lens[S, T], fa State[ST, T], ) Endomorphism[State[ST, S]]
func BindL ¶
func BindL[ST, S, T any]( lens Lens[S, T], f Kleisli[ST, T, T], ) Endomorphism[State[ST, S]]
func LetL ¶
func LetL[ST, S, T any]( lens Lens[S, T], f Endomorphism[T], ) Endomorphism[State[ST, S]]
func LetToL ¶
func LetToL[ST, S, T any]( lens Lens[S, T], b T, ) Endomorphism[State[ST, S]]
type Kleisli ¶
Kleisli represents a Kleisli arrow for the State monad. It's a function from A to State[S, B], which allows composition of stateful computations. This is the fundamental building block for chaining operations that both depend on and modify state.
type Lens ¶
Lens represents a functional reference to a part of a data structure. It's an alias for lens.Lens[S, A] where S is the whole structure and A is the part. Lenses provide composable getters and setters for immutable data structures.
type Operator ¶
Operator is a specialized Kleisli arrow that operates on State values. It transforms a State[S, A] into a State[S, B], making it useful for building pipelines of stateful transformations while maintaining the state type S.
func ApS ¶
func ApS[ST, S1, S2, T any]( setter func(T) func(S1) S2, fa State[ST, T], ) Operator[ST, S1, S2]
func Bind ¶
func Bind[ST, S1, S2, T any]( setter func(T) func(S1) S2, f Kleisli[ST, S1, T], ) Operator[ST, S1, S2]
func ChainFirst ¶
type Pair ¶
Pair represents a tuple of two values of types L and R. It's an alias for pair.Pair[L, R] where L is the head (left) and R is the tail (right).
type Reader ¶
Reader represents a computation that depends on an environment of type R and produces a value of type A. It's an alias for reader.Reader[R, A] and is used for dependency injection patterns.
type State ¶
State represents a stateful computation that takes an initial state of type S, performs some operation, and returns both a new state and a value of type A. It's defined as Reader[S, Pair[S, A]], meaning it's a function that: 1. Takes an initial state S as input 2. Returns a Pair where the head is the new state S and the tail is the computed value A The new state is in the head position and the value in the tail position because the pair monad operates on the tail, allowing monadic operations to transform the computed value while threading the state through the computation.