HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelens-family-core-2.1.3Haskell2010

Lens.Family.State.Lazy

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.

  • 10 types
  • 23 values
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 :: Monad m => FoldLike a s t a b -> StateT s m a
#
use :: Monad m => Getter s t a b -> StateT s m a

Retrieve a field of the state

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

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

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

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

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

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

uses l f = f <$> use l
value(%%=)
  1. :: Monad m
  2. => LensLike (Writer c) s s a b
  3. -> a -> (c, b)
  4. -> StateT s m c
#
(%%=) :: Monad m => Lens s s a b -> (a -> (c, b)) -> StateT s m c

Modify a field of the state while returning another value.

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

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

value(<~) :: Monad m => ASetter s s a b -> StateT s m b -> StateT s m ()
#

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

Compound Assignments

7 declarations

Strict Assignments

8 declarations
value(%!=) :: Monad m => ASetter s s a b -> (a -> b) -> StateT s m ()
#

Strictly modify a field of the state.

Types

1 declaration

Re-exports

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

Constant functor.

Instances28Generic1, Bifoldable, Bifunctor, Bitraversable, Eq2, Ord2, …
newtypenewtype Identity a
#

Identity functor and monad. (a non-strict monad)

Examples
Example1 expression
fmap (+1) (Identity 0)Identity 1
Example1 expression
Identity [1, 2, 3] <> Identity [4, 5, 6]Identity [1,2,3,4,5,6]
>>> do
      x <- Identity 10
      y <- Identity (x + 5)
      pure (x + y)
Identity 25
Instances40Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
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.

Instances12MonadTrans, Monad, Functor, MonadFix, MonadFail, Applicative, …