summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoeyHess <>2018-05-22 21:26:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-05-22 21:26:00 (GMT)
commit3f9db047dc95148d41462d4f928ac2b387134e1c (patch)
tree7244780abd773c28d5ba9a0146aff5bc6a734049
parent8ef6f98cfc1425614e7b4834f80e8a4e80c5eb71 (diff)
version 0.5.00.5.0
-rw-r--r--CHANGELOG8
-rw-r--r--Reactive/Banana/Automation.hs14
-rw-r--r--reactive-banana-automation.cabal2
3 files changed, 18 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 0fadee2..e08bdf0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,11 @@
+reactive-banana-automation (0.5.0) upstream; urgency=medium
+
+ * Remove onEvent, which allowed arbitrary IO not connected with
+ actuators, and so was not good for testing. (API change)
+ * Add actuateEvent.
+
+ -- Joey Hess <id@joeyh.name> Tue, 22 May 2018 17:25:45 -0400
+
reactive-banana-automation (0.4.0) upstream; urgency=medium
* Simplified using ReaderT, so sensors and actuators do not need to be
diff --git a/Reactive/Banana/Automation.hs b/Reactive/Banana/Automation.hs
index 27afd61..fbc58eb 100644
--- a/Reactive/Banana/Automation.hs
+++ b/Reactive/Banana/Automation.hs
@@ -26,7 +26,6 @@ module Reactive.Banana.Automation (
fromEventSource,
gotEvent,
getEventFrom,
- onEvent,
-- * Sensors
Sensed (..),
sensedEvent,
@@ -48,6 +47,7 @@ module Reactive.Banana.Automation (
clockSignalBehavior,
-- * Actuators
PowerChange(..),
+ actuateEvent,
actuateBehavior,
actuateBehaviorMaybe,
-- * Ranges
@@ -114,9 +114,11 @@ instance Functor (Automation sensors actuators) where
instance Monad (Automation sensors actuators) where
return = Automation . return
m >>= g = Automation $ unAutomation m >>= unAutomation . g
+
instance Applicative (Automation sensors actuators) where
pure = Automation . pure
f <*> a = Automation $ unAutomation f <*> unAutomation a
+
instance MonadFix (Automation sensors actuators) where
mfix f = Automation $ mfix (unAutomation . f)
@@ -223,10 +225,6 @@ getEventFrom getsensor = Automation $ do
sensor <- getsensor . fst <$> ask
lift $ fromAddHandler $ addHandler sensor
--- | Runs an action when an event occurs.
-onEvent :: Event a -> (a -> IO ()) -> Automation sensors actuators ()
-onEvent e a = Automation . lift . reactimate $ fmap a e
-
-- | A value read from a sensor.
--
-- Sensors are sometimes not available, or have not provided a value
@@ -379,6 +377,12 @@ clockSignalBehavior getsensor = Automation $ do
data PowerChange = PowerOff | PowerOn
deriving (Show)
+-- | Makes an Event drive an actuator.
+actuateEvent :: Event a -> (a -> actuators) -> Automation sensors actuators ()
+actuateEvent e getactuator = Automation $ do
+ actuators <- snd <$> ask
+ lift $ reactimate $ fmap (actuators . getactuator) e
+
-- | Makes a Behavior drive an actuator. This will happen when the
-- Behavior's value changes, but possibly more often as well, depending on
-- how the Behavior is constructed.
diff --git a/reactive-banana-automation.cabal b/reactive-banana-automation.cabal
index ac41855..48b12fd 100644
--- a/reactive-banana-automation.cabal
+++ b/reactive-banana-automation.cabal
@@ -1,5 +1,5 @@
Name: reactive-banana-automation
-Version: 0.4.0
+Version: 0.5.0
Cabal-Version: >= 1.8
License: AGPL-3
Maintainer: Joey Hess <id@joeyh.name>