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 ()

# 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")`