@@ -82,6 +82,8 @@ module Reflex.Class
82 , zipListWithEvent
82 , zipListWithEvent
83 , numberOccurrences
83 , numberOccurrences
84 , numberOccurrencesFrom
84 , numberOccurrencesFrom
87 , headTailE
89 , headTailE
@@ -926,6 +928,74 @@ numberOccurrences = numberOccurrencesFrom 0
926numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
928numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
927numberOccurrencesFrom = mapAccum_ (\n a -> (n + 1, (n, a)))
929numberOccurrencesFrom = mapAccum_ (\n a -> (n + 1, (n, a)))
931+-- | This is used to sample the value of a 'Behavior' using an 'Event'.
933+-- The '<@>' operator is intended to be used in conjunction with
934+-- the 'Applicative' instance for 'Behavior'.
936+-- This is useful when we want to combine the values of one 'Event' and
937+-- the value of several 'Behavior's at the time the 'Event' is firing.
941+-- > f :: a -> b -> c -> d
942+-- > b1 :: Behavior t a
943+-- > b2 :: Behavior t b
948+-- > f <$> b1 <*> b2 <@> e :: Event t d
950+-- in order to apply the function 'f' to the relevant values.
952+-- The alternative would be something like:
954+-- > attachWith (\(x1, x2) y -> f x1 x2 y) ((,) <$> b1 <*> b2) e :: Event t d
956+-- or a variation involing a custom data type to hold the combination of
957+-- 'Behavior's even when that combination might only ever be used by 'f'.
959+-- A more suggestive example might be:
961+-- > handleMouse <$> bPlayerState <*> bMousePosition <@> eMouseClick :: Event t (GameState -> GameState)
963+(<@>) :: Reflex t => Behavior t (a -> b) -> Event t a -> Event t b
964+(<@>) b = push $ \x -> do
966+ return . Just . f $ x
969+-- | An version of '<@>' that does not use the value of the 'Event'.
971+-- Alternatively, it is 'tag' in operator form.
973+-- This is useful when we want to combine the values of several
974+-- 'Behavior's at particular points in time using an 'Applicative'
979+-- > g :: a -> b -> d
980+-- > b1 :: Behavior t a
981+-- > b2 :: Behavior t b
984+-- where 'e' is firing at the points in time of interest.
986+-- Then we can use '<@':
988+-- > g <$> b1 <*> b2 <@ e :: Event t d
990+-- to combine the values of 'b1' and 'b2' at each of those points of time,
991+-- with the function 'g' being used to combine the values.
993+-- This is the same as '<@>' except that the 'Event' is being used only
994+-- to act as a trigger.
995+(<@) :: (Reflex t) => Behavior t b -> Event t a -> Event t b
929-- | A 'Monad' that supports adjustment over time. After an action has been
999-- | A 'Monad' that supports adjustment over time. After an action has been
930-- run, if the given events fire, it will adjust itself so that its net effect
1000-- run, if the given events fire, it will adjust itself so that its net effect
931-- is as though it had originally been run with the new value. Note that there
1001-- is as though it had originally been run with the new value. Note that there