on develop help sign in
Extend the Reflex class with `now :: PushM t (Event t ())`.
commit446094b733aa6d1e51418d0994889d2cc04fca43 authorAdriaan Leijnse <parenthetical@users.noreply.github.com> dateFri 1 May 2020, 15:00 (6 years ago) parent1d29b35
3 files changed+13
src/Reflex/Class.hs+2 src/Reflex/Pure.hs+3 src/Reflex/Spider/Internal.hs+8
src/Reflex/Class.hs+2
@@ -262,6 +262,8 @@ class ( MonadHold t (PushM t)
262262 never :: Event t a
263263 -- | Create a 'Behavior' that always has the given value
264264 constant :: a -> Behavior t a --TODO: Refactor to use 'pure' from Applicative instead; however, we need to make sure that encouraging Applicative-style use of 'Behavior's doesn't have a negative performance impact
265+ -- | An event which occurs at the current moment.
266+ now :: PushM t (Event t ())
265267 -- | Create an 'Event' from another 'Event'; the provided function can sample
266268 -- 'Behavior's and hold 'Event's, and use the results to produce a occurring
267269 -- (Just) or non-occurring (Nothing) result
src/Reflex/Pure.hs+3
@@ -66,6 +66,9 @@ instance (Enum t, HasTrie t, Ord t) => Reflex (Pure t) where
6666 constant :: a -> Behavior (Pure t) a
6767 constant x = Behavior $ \_ -> x
6868
69+ now :: PushM (Pure t) (Event (Pure t) ())
70+ now t = Event $ guard . (t ==)
71+
6972 push :: (a -> PushM (Pure t) (Maybe b)) -> Event (Pure t) a -> Event (Pure t) b
7073 push f e = Event $ memo $ \t -> unEvent e t >>= \o -> f o t
7174
src/Reflex/Spider/Internal.hs+8
@@ -415,6 +415,12 @@ subscribeAndReadNever = return (EventSubscription (return ()) eventSubscribedNev
415415eventNever :: Event x a
416416eventNever = Event $ const subscribeAndReadNever
417417
418+eventNow :: Event x ()
419+eventNow = Event . const . pure $
420+ ( EventSubscription (return ()) eventSubscribedNever
421+ , Just ()
422+ )
423+
418424eventFan :: (GCompare k, HasSpiderTimeline x) => k a -> Fan x k v -> Event x (v a)
419425eventFan !k !f = Event $ wrap eventSubscribedFan $ getFanSubscribed k f
420426
@@ -2729,6 +2735,8 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
27292735 never = SpiderEvent eventNever
27302736 {-# INLINABLE constant #-}
27312737 constant = SpiderBehavior . behaviorConst
2738+ {-# INLINABLE now #-}
2739+ now = pure . SpiderEvent $ eventNow
27322740 {-# INLINE push #-}
27332741 push f = SpiderEvent . push (coerce f) . unSpiderEvent
27342742 {-# INLINE pushCheap #-}