-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Monoidal, monadic and first-class events
--   
--   This package can be used to represent events as first-class objects
--   instead of deepening callbacks and nesting callbacks. Useful to wrap
--   over <b>C</b> callback-based libraries.
@package event
@version 0.1.4


-- | An <tt><a>Event</a> a</tt> is an object representing an event of type
--   <tt>a</tt>. You can register actions through it – see the <a>on</a>
--   function – and detach them later on.
--   
--   An <a>Event</a> has many purposes. The one in mind when writing that
--   package was to interface over <b>C</b> callback-based reactive system.
--   Consider the following <b>Haskell</b> wrapper function, which is based
--   on imperative style:
--   
--   <pre>
--   -- Create a new button and register an action to launch when the button’s
--   -- state changes.
--   createButton :: (ButtonState -&gt; IO ()) -&gt; IO Button
--   createButton callback = do
--     -- create the button
--     button &lt;- ...
--     forkIO . forever $ do
--       -- launch a thread in which we can test whether the state has changed
--       when stateHasChanged $ callback newState
--     pure button
--   </pre>
--   
--   We can enhance that by representing the action of registering to the
--   event and detaching from it by immediately returning a value:
--   
--   <pre>
--   createButton :: IO (Button,Event ButtonState)
--   createButton = do
--     -- create the button
--     button &lt;- ...
--     -- create an <a>Event</a>
--     (ev,t) &lt;- newEvent
--     forkIO . forever $
--       -- check the new state
--       when stateHasChanged $ trigger t newState
--     pure (button,ev)
--   </pre>
--   
--   The <a>Trigger</a> can also be returned to manually invoke the
--   <a>Event</a>.
module Control.Concurrent.Event

-- | An <tt><a>Event</a> a</tt> is a value of type <tt>a</tt> with no
--   direct representation. It lives <i>in the future</i>. It’s possible to
--   register actions with <a>on</a> to execute when data becomes
--   available, and to detach those actions with the resulting
--   <a>Detach</a> object by calling <a>detach</a> on it.
--   
--   <a>Event</a>s can be triggered with the <a>trigger</a> function and
--   the associated type <a>Trigger</a>.
data Event a

-- | <a>Detach</a> is used to detach an action from an <a>Event</a>.
newtype Detach
Detach :: IO () -> Detach
[detach] :: Detach -> IO ()

-- | Register an action.
on :: (MonadIO m) => Event a -> (a -> IO ()) -> m Detach

-- | Create a new <tt><a>Event</a> a</tt> along with a <tt><a>Trigger</a>
--   a</tt>.
newEvent :: (MonadIO m) => m (Event a, Trigger a)

-- | <tt><a>Trigger</a> a</tt> is used to <a>trigger</a> an
--   <tt><a>Event</a> a</tt>.
newtype Trigger a
Trigger :: (a -> IO ()) -> Trigger a

-- | Use a <a>Trigger</a>.
trigger :: (MonadIO m) => Trigger a -> a -> m ()

-- | Filter an <a>Event</a> with a predicate.
filterE :: (a -> Bool) -> Event a -> Event a

-- | Right fold an <a>Event</a>. Each time an event occur, the function
--   folding function is applied and the result is passed to the future
--   <a>Event</a>.
foldrE :: (b -> a -> b) -> b -> Event a -> Event b
instance GHC.Base.Monoid (Control.Concurrent.Event.Trigger a)
instance GHC.Base.Semigroup (Control.Concurrent.Event.Trigger a)
instance GHC.Base.Applicative Control.Concurrent.Event.Event
instance GHC.Base.Functor Control.Concurrent.Event.Event
instance GHC.Base.Monad Control.Concurrent.Event.Event
instance GHC.Base.Monoid (Control.Concurrent.Event.Event a)
instance GHC.Base.Semigroup (Control.Concurrent.Event.Event a)
instance GHC.Base.Monoid Control.Concurrent.Event.Detach
instance GHC.Base.Semigroup Control.Concurrent.Event.Detach
