Repository navigation
Extend the Reflex class with now :: PushM t (Event t ()). (Issue #414) - #416
Conversation
now :: PushM t (Event t ()). (#414)now :: PushM t (Event t ()). (Issue #414)
|
Overall this looks good. Would you mind adding a new EventSubscribed, instead of reusing reflex/src/Reflex/Spider/Internal.hs Line 599 in 446094b Also, we'll need some tests for this. |
|
I'll change that and try to add some tests as well, thanks! |
|
Does this look better? |
|
Can we add a test showing that it is not firing at some times other than the time it's created? I think it might need an IORef or something - this looks like it is probably always firing (but only the first time each subscriber looks at it). |
|
Thanks for the hints; I implemented it with an IORef and added a test case for the always firing issue. |
|
Awesome! That looks right to me :) Only two things left:
|
|
Great, thanks for the shepherding! |
|
Hmm, well, putting it in a typeclass seems like a perfectly reasonable thing to do. Note that not all implementations of MonadSample or MonadHold will have implementations for |
| -- the supplied 'Event'. | ||
| headE :: Event t a -> m (Event t a) | ||
| -- | An event which occurs at the current moment. | ||
| now :: m (Event t ()) |
There was a problem hiding this comment.
I added this if that's what you're thinking of?
-- | An event which only occurs at the current moment in time, such that:
--
-- > coincidence (pushAlways (\a -> (a <$) <$> now) e) = e
--
now :: m (Event t ())
Also, now turns events in the context of a MonadHold into an applicative functor and monad using the existing Apply and Bind instances:
instance (..., MonadHold t m) => Applicative (m . Event t) where
pure a = (a <$) <$> now
(<$>) = liftA2 (<.>)
|
Awesome, thanks! |
I hope the implementation in Spider is correct, it produced the expected result when testing with
switchHoldPromptly never . pushAlways (\a -> fmap (a <$) now).Extending the Reflex class might break modules depending on Reflex if they or another dependency use
nowas an identifier. Let me know if that's not okay.The change is motivated by distributed Reflex (coming soon™), in which
you can write things like:
Maybe there are other use cases as well?