Safe Haskell | Safe-Inferred |
---|

A module extending the functionality of the State Monad with Views

- module Control.Monad.State
- module Data.View
- viewState :: MonadState s m => View s t -> (t -> (a, t)) -> m a
- viewing :: MonadState s m => View s t -> State t a -> m a
- modifying :: MonadState s m => View s t -> (t -> t) -> m ()
- getting :: MonadState s m => View s a -> m a
- putting :: MonadState s m => View s t -> t -> m ()
- swappingWith :: MonadState s m => View s t -> (t -> t) -> m b -> m b
- swapping :: MonadState s m => View s t -> t -> m b -> m b
- saving :: MonadState s m => View s t -> m b -> m b

# Documentation

module Control.Monad.State

module Data.View

# Views with State

viewState :: MonadState s m => View s t -> (t -> (a, t)) -> m aSource

Constructs a State monad that acts on a View.

viewing :: MonadState s m => View s t -> State t a -> m aSource

Executes a state restricted to the given View.

modifying :: MonadState s m => View s t -> (t -> t) -> m ()Source

Modifies the view by the given function. `modifying v f`

is equivalent to `viewing v (modify f)`

.

getting :: MonadState s m => View s a -> m aSource

Gets the given view from the whole state

putting :: MonadState s m => View s t -> t -> m ()Source

Injects the given value into the whole state. `putting v x`

is equivalent to `viewing v (put x)`

.

swappingWith :: MonadState s m => View s t -> (t -> t) -> m b -> m bSource

`swappingWith v f m`

executes `m`

in an environment where the view `v`

was modified by `f`

,
preserving the old value of `v`

(it swaps the old value and the new, and then swaps back after `m`

)

swapping :: MonadState s m => View s t -> t -> m b -> m bSource

A special case of `swappingWith`

with a constant value.

saving :: MonadState s m => View s t -> m b -> m bSource

`saving v m`

executes `m`

, while preserving the value of the View `v`

.