views-1.0: Views allow you to run a State monad on part of a state.

Safe HaskellSafe-Inferred

Control.Monad.State.View

Contents

Description

A module extending the functionality of the State Monad with Views

Synopsis

Documentation

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.