Module

Control.Monad.Eff.Ref

Package
purescript-refs
Repository
purescript/purescript-refs

This module defines an effect and actions for working with global mutable variables.

Note: The Control.Monad.ST provides a safe alternative to global mutable variables when mutation is restricted to a local scope.

#REF Source

data REF :: Effect

The effect associated with the use of global mutable variables.

#Ref Source

data Ref :: Type -> Type

A value of type Ref a represents a mutable reference which holds a value of type a.

#newRef Source

newRef :: forall r s. s -> Eff (ref :: REF | r) (Ref s)

Create a new mutable reference containing the specified value.

#readRef Source

readRef :: forall r s. Ref s -> Eff (ref :: REF | r) s

Read the current value of a mutable reference

#modifyRef' Source

modifyRef' :: forall r b s. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b

Update the value of a mutable reference by applying a function to the current value.

#modifyRef Source

modifyRef :: forall r s. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit

Update the value of a mutable reference by applying a function to the current value.

#writeRef Source

writeRef :: forall r s. Ref s -> s -> Eff (ref :: REF | r) Unit

Update the value of a mutable reference to the specified value.