I use Reflex inside Haskell, and try to create an event that fires (for questions) a given period of time after another, say 2 seconds. However, the counter must reset whenever the source event occurs, so if the source event fires twice for 1 second, only one second event is needed: 2 seconds after the last original event.
I managed to implement this behavior with
delayedReset :: MonadWidget t m => Event t () -> m (Event t ())
delayedReset ev = fmap (switch . current) . widgetHold (return never) $ timer <$ ev
where
timer = delay 2 =<< getPostBuild
but it seems unnecessary to use widgetHold; it seems that we really only need a MonadHold restriction. Is there a more idiomatic way to write this function?
source
share