Safe Haskell | None |
---|---|

Language | Haskell2010 |

This module contains utilities for working with `Setter`

s in a `MonadState`

context. If you prefer operator versions, you may wish to import
Optics.State.Operators.

## Synopsis

- modifying :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> (a -> b) -> m ()
- modifying' :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> (a -> b) -> m ()
- assign :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> b -> m ()
- assign' :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> b -> m ()
- use :: (Is k A_Getter, MonadState s m) => Optic' k is s a -> m a
- preuse :: (Is k An_AffineFold, MonadState s m) => Optic' k is s a -> m (Maybe a)

# Documentation

modifying :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> (a -> b) -> m () Source #

Map over the target(s) of an `Optic`

in our monadic state.

`>>>`

(60,"ooooo")`execState (do modifying _1 (*10); modifying _2 $ stimes 5) (6,"o")`

`>>>`

("aa","bb")`execState (modifying each $ stimes 2) ("a","b")`

modifying' :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> (a -> b) -> m () Source #

Version of `modifying`

that is strict in both optic application and state
modification.

`>>>`

()`flip evalState ('a','b') $ modifying _1 (errorWithoutStackTrace "oops")`

`>>>`

*** Exception: oops`flip evalState ('a','b') $ modifying' _1 (errorWithoutStackTrace "oops")`

assign :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> b -> m () Source #

Replace the target(s) of an `Optic`

in our monadic state with a new value,
irrespective of the old.

`>>>`

('c','d')`execState (do assign _1 'c'; assign _2 'd') ('a','b')`

`>>>`

('c','c')`execState (assign each 'c') ('a','b')`

assign' :: (Is k A_Setter, MonadState s m) => Optic k is s s a b -> b -> m () Source #

Version of `assign`

that is strict in both optic application and state
modification.

`>>>`

()`flip evalState ('a','b') $ assign _1 (errorWithoutStackTrace "oops")`

`>>>`

*** Exception: oops`flip evalState ('a','b') $ assign' _1 (errorWithoutStackTrace "oops")`

preuse :: (Is k An_AffineFold, MonadState s m) => Optic' k is s a -> m (Maybe a) Source #

Use the target of a `AffineTraveral`

or `AffineFold`

in the current state.

`>>>`

Just 'a'`evalState (preuse $ _1 % _Right) (Right 'a','b')`

*Since: 0.2*