HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelens-family-2.1.3Haskell2010

Lens.Family2.State.Strict

Lenses allow you to use fields of the state of a state monad as if they were variables in an imperative language. use is used to retrieve the value of a variable, and .= and %= allow you to set and modify a variable. C-style compound assignments are also provided.

  • 9 types
  • 2 classes
  • 23 values
  • Packagelens-family-2.1.3
  • Exports34
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceStrict.hs
valuezoom
  1. :: Monad m
  2. => LensLike' (Zooming m c) s a
  3. -> StateT a m c
  4. -> StateT s m c
#
zoom :: Monad m => Lens' s a -> StateT a m c -> StateT s m c

Lift a stateful operation on a field to a stateful operation on the whole state. This is a good way to call a "subroutine" that only needs access to part of the state.

zoom :: (Monad m, Monoid c) => Traversal' s a -> StateT a m c -> StateT s m c

Run the "subroutine" on each element of the traversal in turn and mconcat all the results together.

zoom :: Monad m => Traversal' s a -> StateT a m () -> StateT s m ()

Run the "subroutine" on each element the traversal in turn.

valueuse :: MonadState s m => FoldLike a s t a b -> m a
#
use :: MonadState s m => Getter s t a b -> m a

Retrieve a field of the state

use :: (MonadState s m, Monoid a) => Fold s t a b -> m a

Retrieve a monoidal summary of all the referenced fields from the state

valueuses :: MonadState s m => FoldLike r s t a b -> (a -> r) -> m r
#
uses :: (MonadState s m, Monoid r) => Fold s t a b -> (a -> r) -> m r

Retrieve all the referenced fields from the state and foldMap the results together with f :: a -> r.

uses :: MonadState s m => Getter s t a b -> (a -> r) -> m r

Retrieve a field of the state and pass it through the function f :: a -> r.

uses l f = f <$> use l
value(%=) :: MonadState s m => Setter s s a b -> (a -> b) -> m ()
#

Modify a field of the state.

value(%%=)
  1. :: MonadState s m
  2. => LensLike (Writer c) s s a b
  3. -> a -> (c, b)
  4. -> m c
#
(%%=) :: MonadState s m => Lens s s a b -> (a -> (c, b)) -> m c

Modify a field of the state while returning another value.

(%%=) :: (MonadState s m, Monoid c) => Traversal s s a b -> (a -> (c, b)) -> m c

Modify each field of the state and return the mconcat of the other values.

value(<~) :: MonadState s m => Setter s s a b -> m b -> m ()
#

Set a field of the state using the result of executing a stateful command.

Compound Assignments

7 declarations
value(<>=) :: (MonadState s m, Monoid a) => Setter' s a -> a -> m ()
#

Monoidally append a value to all referenced fields of the state.

Strict Assignments

8 declarations
value(%!=) :: MonadState s m => Setter s s a b -> (a -> b) -> m ()
#

Strictly modify a field of the state.

Types

1 declaration

Re-exports

10 declarations
newtypenewtype Constant a (b :: k)
#

Constant functor.

Instances28Generic1, Bifoldable, Bifunctor, Bitraversable, Eq2, Ord2, …
newtypenewtype StateT s (m :: Type -> Type) a
#

A state transformer monad parameterized by:

  • s - The state.

  • m - The inner monad.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

Instances19MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, MonadSelect, …
classclass Monad m => MonadState s (m :: Type -> Type) | m -> s where
#

Minimal definition is either both of get and put or just state

Instances15MonadState, …