simple-observer-0.0.1: The Observer pattern

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.

Synopsis

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.

Instances

Subject (Sub a) a 

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.

addConstObserver :: Subject sub val => sub -> IO () -> IO ()Source

Add an observer which doesn't care about the subject's value, only that it's changed.