Control.Observer
Description
An implementation of the Observer pattern, based on Observable.hs by Bastiaan Heeren, originally from http://www.cs.uu.nl/wiki/bin/view/Afp0607/ExerciseWXHaskell
This module defines the Subject
typeclass, specifying the
capabilities of an observable value. See other modules in the package
for example implementations of this typeclass.
Documentation
class Subject sub val | sub -> val whereSource
A type class for observable objects. A minimal implementation implements all of these functions.
Methods
getValue :: sub -> IO valSource
Get the subject's current value.
setValue' :: sub -> val -> IO ()Source
Update the subject's value quietly; should NOT call
notifyObservers. Rarely called; usually you want setValue
,
which does notify the subject's observers of the change.
addObserver :: sub -> (val -> IO ()) -> IO ()Source
Add an observer function.
getObservers :: sub -> IO [val -> IO ()]Source
Get the list of observers.
setValue :: Subject sub val => sub -> val -> IO ()Source
Update the subject value, and notify observers.
notifyObservers :: Subject sub val => sub -> IO ()Source
Notify observers that the subject's value has changed. Rarely
called explicitly: usually called via setValue
.
changeValue :: Subject sub val => sub -> (val -> val) -> IO ()Source
Apply an update function to the subject value, and notify observers.