Copyright | (c) 2016 Allele Dev; 2017 Ixperta Solutions s.r.o. |
---|---|

License | BSD3 |

Maintainer | ixcom-core@ixperta.com |

Stability | experimental |

Portability | GHC specific language extensions. |

Safe Haskell | None |

Language | Haskell2010 |

Composable handler for `State`

effects. Handy for passing an updatable state
through a computation.

Some computations may not require the full power of `State`

effect:

- For a read-only state, see Control.Monad.Freer.Reader.
- To accumulate a value without using it on the way, see Control.Monad.Freer.Writer.

Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a starting point.

- data State s a where
- get :: Member (State s) effs => Eff effs s
- put :: Member (State s) effs => s -> Eff effs ()
- modify :: Member (State s) effs => (s -> s) -> Eff effs ()
- runState :: Eff (State s ': effs) a -> s -> Eff effs (a, s)
- evalState :: Eff (State s ': effs) a -> s -> Eff effs a
- execState :: Eff (State s ': effs) a -> s -> Eff effs s
- transactionState :: forall s effs a. Member (State s) effs => Proxy s -> Eff effs a -> Eff effs a

# State Effect

# State Operations

get :: Member (State s) effs => Eff effs s Source #

Retrieve the current value of the state of type `s :: *`

.

put :: Member (State s) effs => s -> Eff effs () Source #

Set the current state to a specified value of type `s :: *`

.

modify :: Member (State s) effs => (s -> s) -> Eff effs () Source #

Modify the current state of type `s :: *`

using provided function
`(s -> s)`

.

# State Handlers

evalState :: Eff (State s ': effs) a -> s -> Eff effs a Source #

Run a State effect, discarding the final state.

execState :: Eff (State s ': effs) a -> s -> Eff effs s Source #

Run a `State`

effect, returning only the final state.

# State Utilities

transactionState :: forall s effs a. Member (State s) effs => Proxy s -> Eff effs a -> Eff effs a Source #

An encapsulated State handler, for transactional semantics. The global
state is updated only if the `transactionState`

finished successfully.