-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
@@ -420,6 +420,10 @@ class MonadSample t m => MonadHold t m where | |||
-- | Create a new 'Event' that only occurs only once, on the first occurrence of | |||
-- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can any laws be documented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
now
as 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?