@@ -80,6 +80,8 @@ module Reflex.Class
80 , mapAccumMaybe_
80 , mapAccumMaybe_
81 , mapAccumMaybeM_
81 , mapAccumMaybeM_
82 , zipListWithEvent
82 , zipListWithEvent
85 , headTailE
87 , headTailE
@@ -916,6 +918,76 @@ zipListWithEvent f l e = do
916 _ -> (Nothing, Nothing) --TODO: Unsubscribe the event?
918 _ -> (Nothing, Nothing) --TODO: Unsubscribe the event?
917 mapAccumMaybe_ f' l e
919 mapAccumMaybe_ f' l e
923+-- | This is used to sample the value of a 'Behavior' using an 'Event'.
925+-- The '<@>' operator is intended to be used in conjunction with
926+-- the 'Applicative' instance for 'Behavior'.
928+-- This is useful when we want to combine the values of one 'Event' and
929+-- the value of several 'Behavior's at the time the 'Event' is firing.
933+-- > f :: a -> b -> c -> d
934+-- > b1 :: Behavior t a
935+-- > b2 :: Behavior t b
940+-- > f <$> b1 <*> b2 <@> e :: Event t d
942+-- in order to apply the function 'f' to the relevant values.
944+-- The alternative would be something like:
946+-- > attachWith (\(x1, x2) y -> f x1 x2 y) ((,) <$> b1 <*> b2) e :: Event t d
948+-- or a variation involing a custom data type to hold the combination of
949+-- 'Behavior's even when that combination might only ever be used by 'f'.
951+-- A more suggestive example might be:
953+-- > handleMouse <$> bPlayerState <*> bMousePosition <*> eMouseClick :: Event t (GameState -> GameState)
955+(<@>) :: Reflex t => Behavior t (a -> b) -> Event t a -> Event t b
956+(<@>) b = push $ \x -> do
958+ return . Just . f $ x
962+-- | An version of '<@>' that does not use the value of the 'Event'.
964+-- Alternatively, it is 'tag' in operator form.
966+-- This is useful when we want to combine the values of several
967+-- 'Behavior's at particular points in time using an 'Applicative'
972+-- > g :: a -> b -> d
973+-- > b1 :: Behavior t a
974+-- > b2 :: Behavior t b
977+-- where 'e' is firing at the points in time of interest.
979+-- Then we can use '<@':
981+-- > g <$> b1 <*> b2 <@ e :: Event t d
983+-- to combine the values of 'b1' and 'b2' at each of those points of time,
984+-- with the function 'g' being used to combine the values.
986+-- This is the same as '<@>' except that the 'Event' is being used only
987+-- to act as a trigger.
988+(<@) :: (Reflex t) => Behavior t b -> Event t a -> Event t b
919-- | A 'Monad' that supports adjustment over time. After an action has been
991-- | A 'Monad' that supports adjustment over time. After an action has been
920-- run, if the given events fire, it will adjust itself so that its net effect
992-- run, if the given events fire, it will adjust itself so that its net effect
921-- is as though it had originally been run with the new value. Note that there
993-- is as though it had originally been run with the new value. Note that there