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

Moduleoptics-extra-0.4.2.1Haskell2010

Optics.State

This module contains utilities for working with Setters in a MonadState context. If you prefer operator versions, you may wish to import Optics.State.Operators.

  • 6 values
valuemodifying
  1. :: (Is k A_Setter, MonadState s m)
  2. => Optic k is s s a b
  3. -> a -> b
  4. -> m ()
#

Map over the target(s) of an Optic in our monadic state.

Example1 expression
execState (do modifying _1 (*10); modifying _2 $ stimes 5) (6,"o")(60,"ooooo")
Example1 expression
execState (modifying each $ stimes 2) ("a","b")("aa","bb")
valuemodifying'
  1. :: (Is k A_Setter, MonadState s m)
  2. => Optic k is s s a b
  3. -> a -> b
  4. -> m ()
#

Version of modifying that is strict in both optic application and state modification.

Example1 expression
flip evalState ('a','b') $ modifying _1 (errorWithoutStackTrace "oops")()
Example1 expression
flip evalState ('a','b') $ modifying' _1 (errorWithoutStackTrace "oops")*** Exception: oops
valueassign :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> b -> m ()
#

Replace the target(s) of an Optic in our monadic state with a new value, irrespective of the old.

Example1 expression
execState (do assign _1 'c'; assign _2 'd') ('a','b')('c','d')
Example1 expression
execState (assign each 'c') ('a','b')('c','c')
valueassign'
  1. :: (Is k A_Setter, MonadState s m)
  2. => Optic k is s s a b
  3. -> b
  4. -> m ()
#

Version of assign that is strict in both optic application and state modification.

Example1 expression
flip evalState ('a','b') $ assign _1 (errorWithoutStackTrace "oops")()
Example1 expression
flip evalState ('a','b') $ assign' _1 (errorWithoutStackTrace "oops")*** Exception: oops
valueuse :: (Is k A_Getter, MonadState s m) => Optic' k is s a -> m a
#

Use the target of a Lens, Iso, or Getter in the current state.

Example1 expression
evalState (use _1) ('a','b')'a'
Example1 expression
evalState (use _2) ("hello","world")"world"