program-0.1.0.0: Programs with Environments and Managed Resources
Copyright(c) Michael Szvetits 2021
LicenseBSD3 (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Program.State

Description

Types and functions for handling mutable state in the environment of a Program.

Synopsis

State Effect

data State s Source #

A record of functions which represents the operations on a mutable value.

Constructors

State 

Fields

Program-based State

get :: e `Has` State s => Program e s Source #

Gets the current state.

put :: e `Has` State s => s -> Program e () Source #

Replaces the state with a new value.

modify :: e `Has` State s => (s -> s) -> Program e () Source #

Modifies the state, using the provided function.

modify' :: e `Has` State s => (s -> s) -> Program e () Source #

A strict version of modify.

IO-based State

newState :: s -> IO (State s) Source #

Creates a new record of functions for mutable state, backed by an IORef.

modifyState :: State s -> (s -> s) -> IO () Source #

Modifies the state, using the provided function.

modifyState' :: State s -> (s -> s) -> IO () Source #

A strict version of modifyState.