on develop help sign in
Add switchPromptOnly and fix the docs for switchPromptly. Closes #74.
8d1443eRyan Trinkle
src/Reflex/Class.hs+10−3
@@ -56,6 +56,7 @@ module Reflex.Class
56 , dsumToEither
56 , dsumToEither
57 -- ** Switching between 'Event's
57 -- ** Switching between 'Event's
58 , switchPromptly
58 , switchPromptly
59+ , switchPromptOnly
59 -- ** Using 'Event's to sample 'Behavior's
60 -- ** Using 'Event's to sample 'Behavior's
60 , tag
61 , tag
61 , attach
62 , attach
@@ -683,15 +684,21 @@ fanThese e =
683fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)
684fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)
684fanMap = fan . fmap mapToDMap
685fanMap = fan . fmap mapToDMap
685
686
686−-- | Switches to the new event whenever it receives one; the new event is used
687+-- | Switches to the new event whenever it receives one. Whenever a new event
687−-- immediately, on the same frame that it is switched to
688+-- is provided, if it is firing, its value will be the resulting event's value;
689+-- if it is not firing, but the old one is, the old one's value will be used.
688−switchPromptly :: forall t m a. (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
690+switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
689switchPromptly ea0 eea = do
691switchPromptly ea0 eea = do
690 bea <- hold ea0 eea
692 bea <- hold ea0 eea
691 let eLag = switch bea
693 let eLag = switch bea
692 eCoincidences = coincidence eea
694 eCoincidences = coincidence eea
693 return $ leftmost [eCoincidences, eLag]
695 return $ leftmost [eCoincidences, eLag]
694
696
697+switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
698+switchPromptOnly e0 e' = do
699+ eLag <- switch <$> hold e0 e'
700+ return $ coincidence $ leftmost [e', eLag <$ eLag]
701+
695instance Reflex t => Align (Event t) where
702instance Reflex t => Align (Event t) where
696 nil = never
703 nil = never
697 align = alignWithMaybe Just
704 align = alignWithMaybe Just