You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--| A container for a value that can change over time. Behaviors can be sampled at will, but it is not possible to be notified when they change
25
32
dataBehaviort::*->*
26
33
--| A stream of occurrences. During any given frame, an Event is either occurring or not occurring; if it is occurring, it will contain a value of the given type (its "occurrence type")
@@ -39,14 +46,14 @@ class (MonadHold t (PushM t), MonadSample t (PullM t), Functor (Event t), Functo
39
46
typePullMt::*->*
40
47
--| Merge a collection of events; the resulting Event will only occur if at least one input event is occuring, and will contain all of the input keys that are occurring simultaneously
41
48
merge::GComparek=>DMap (WrapArg (Eventt) k) ->Eventt (DMapk) --TODO: Generalize to get rid of DMap use --TODO: Provide a type-level guarantee that the result is not empty
42
-
--| Efficiently fan-out an event to many destinations. This function should be partially applied, and then the result applied repeatedly to create child events
49
+
--| Efficiently fan-out an event to many destinations. This function should be partially applied, and then the result applied repeatedly to create child events
43
50
fan::GComparek=>Eventt (DMapk) ->EventSelectortk--TODO: Can we help enforce the partial application discipline here? The combinator is worthless without it
44
51
--| Create an Event that will occur whenever the currently-selected input Event occurs
45
52
switch::Behaviort (Eventta) ->Eventta
46
53
--| Create an Event that will occur whenever the input event is occurring and its occurrence value, another Event, is also occurring
-- Note: it is tempting to write (_ >> b = b); however, this would result in (fail x >> return y) succeeding (returning y), which violates the law that (a >> b = a >>= \_ -> b), since the implementation of (>>=) above actually will fail. Since we can't examine Behaviors other than by using sample, I don't think it's possible to write (>>) to be more efficient than the (>>=) above.
131
+
return= constant
132
+
fail=error"Monad (Behavior t) does not support fail"
133
+
134
+
instance (Reflext, Semigroupa) =>Semigroup (Behaviorta) where
135
+
a <> b = pull $ liftM2 (<>) (sample a) (sample b)
136
+
sconcat = pull . liftM sconcat .mapM sample
137
+
times1p n =fmap$ times1p n
138
+
139
+
instance (Reflext, Monoida) =>Monoid (Behaviorta) where
140
+
mempty= constant mempty
141
+
mappend a b = pull $ liftM2 mappend (sample a) (sample b)
142
+
mconcat= pull . liftM mconcat.mapM sample
143
+
85
144
--TODO: See if there's a better class in the standard libraries already
86
145
--| A class for values that combines filtering and mapping using 'Maybe'.
87
146
classFunctorMaybefwhere
@@ -239,7 +298,7 @@ dmapToThese m = case (DMap.lookup LeftTag m, DMap.lookup RightTag m) of
239
298
-- 'Event's occurs. If both occur at the same time they are combined
0 commit comments