Module

Effect.Ref

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

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

#Ref

data Ref :: Type -> Type

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

#new

new :: forall s. s -> Effect (Ref s)

Create a new mutable reference containing the specified value.

#read

read :: forall s. Ref s -> Effect s

Read the current value of a mutable reference

#modify'

modify' :: forall s b. (s -> { state :: s, value :: b }) -> Ref s -> Effect b

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

#modify

modify :: forall s. (s -> s) -> Ref s -> Effect s

Update the value of a mutable reference by applying a function to the current value. The updated value is returned.

#modify_

modify_ :: forall s. (s -> s) -> Ref s -> Effect Unit

#write

write :: forall s. s -> Ref s -> Effect Unit

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

Modules