reactive-banana-1.3.2.0: Library for functional reactive programming (FRP).

Safe Haskell | Safe-Inferred
Language | Haskell98

Control.Event.Handler

Contents

- Synopsis
- Documentation

Synopsis

- type Handler a = a -> IO ()
- newtype AddHandler a = AddHandler {
  - register :: Handler a -> IO (IO ())
  }
- newAddHandler :: IO (AddHandler a, Handler a)
- mapIO :: (a -> IO b) -> AddHandler a -> AddHandler b
- filterIO :: (a -> IO Bool) -> AddHandler a -> AddHandler a

# Synopsis

Event-driven programming in the traditional imperative style.

# Documentation

type Handler a = a -> IO () Source #

An event handler is a function that takes an event value and performs some computation.

newtype AddHandler a Source #

The type `AddHandler` represents a facility for registering event handlers. These will be called whenever the event occurs.

When registering an event handler, you will also be given an action that unregisters this handler again.

    do unregisterMyHandler <- register addHandler myHandler

Constructors

AddHandler |

Fields

- register :: Handler a -> IO (IO ())

#### Instances

Instances details

Functor AddHandler Source # |
Instance details Defined in Control.Event.Handler Methods fmap :: (a -> b) -> AddHandler a -> AddHandler b Source # (<$) :: a -> AddHandler b -> AddHandler a Source #

newAddHandler :: IO (AddHandler a, Handler a) Source #

Build a facility to register and unregister event handlers. Also yields a function that takes an event handler and runs all the registered handlers.

Example:

    do
        (addHandler, fire) <- newAddHandler
        register addHandler putStrLn
        fire "Hello!"

mapIO :: (a -> IO b) -> AddHandler a -> AddHandler b Source #

Map the event value with an `IO` action.

filterIO :: (a -> IO Bool) -> AddHandler a -> AddHandler a Source #

Filter event values that don't return `True`.