miso
Copyright(C) 2016-2025 David M. Johnson (@dmjio)
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Miso.State

Description

Similar to how one manages state in React, miso applications manage state with the State monad.

The State Monad works well with MonadState lenses as seen in Lens and the lens library.

updateModel :: Action -> Effect Model Action
updateModel (AddOne event) = do
  modify (+1)
  io_ (consoleLog "Added One!")

This module re-exports select combinators from RWS and serves as a placeholder to add new state management combinators.

Synopsis

Documentation

ask :: MonadReader r m => m r #

Retrieves the monad environment.

modify :: MonadState s m => (s -> s) -> m () #

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

     Main> :t modify ((+1) :: Int -> Int)
     modify (...) :: (MonadState Int a) => a ()

This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.

modify' :: MonadState s m => (s -> s) -> m () #

A variant of modify in which the computation is strict in the new state.

Since: mtl-2.2

get :: MonadState s m => m s #

Return the state from the internals of the monad.

gets :: MonadState s m => (s -> a) -> m a #

Gets specific component of the state, using a projection function supplied.

put :: MonadState s m => s -> m () #

Replace the state inside the monad.

tell :: MonadWriter w m => w -> m () #

tell w is an action that produces the output w.