on develop help sign in
Add switchPromptOnly and fix the docs for switchPromptly. Closes #74.
commit8d1443e204bbd81df2b5d47953e161d15e829236 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSun 13 Nov 2016, 15:13 (10 years ago) parentba77fac
1 file changed+10−3
src/Reflex/Class.hs+10−3
src/Reflex/Class.hs+10−3
@@ -56,6 +56,7 @@ module Reflex.Class
5656 , dsumToEither
5757 -- ** Switching between 'Event's
5858 , switchPromptly
59+ , switchPromptOnly
5960 -- ** Using 'Event's to sample 'Behavior's
6061 , tag
6162 , attach
@@ -683,15 +684,21 @@ fanThese e =
683684fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)
684685fanMap = fan . fmap mapToDMap
685686
686−-- | Switches to the new event whenever it receives one; the new event is used
687−-- immediately, on the same frame that it is switched to
688−switchPromptly :: forall t m a. (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
687+-- | Switches to the new event whenever it receives one. Whenever a new event
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.
690+switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
689691switchPromptly ea0 eea = do
690692 bea <- hold ea0 eea
691693 let eLag = switch bea
692694 eCoincidences = coincidence eea
693695 return $ leftmost [eCoincidences, eLag]
694696
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+
695702instance Reflex t => Align (Event t) where
696703 nil = never
697704 align = alignWithMaybe Just