on develop help sign in
Extend the Reflex class with `now :: PushM t (Event t ())`.
446094bAdriaan Leijnse
src/Reflex/Class.hs+2
@@ -262,6 +262,8 @@ class ( MonadHold t (PushM t)
262 never :: Event t a
262 never :: Event t a
263 -- | Create a 'Behavior' that always has the given value
263 -- | Create a 'Behavior' that always has the given value
264 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
264 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 ())
265 -- | Create an 'Event' from another 'Event'; the provided function can sample
267 -- | Create an 'Event' from another 'Event'; the provided function can sample
266 -- 'Behavior's and hold 'Event's, and use the results to produce a occurring
268 -- 'Behavior's and hold 'Event's, and use the results to produce a occurring
267 -- (Just) or non-occurring (Nothing) result
269 -- (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
66 constant :: a -> Behavior (Pure t) a
66 constant :: a -> Behavior (Pure t) a
67 constant x = Behavior $ \_ -> x
67 constant x = Behavior $ \_ -> x
68
68
69+ now :: PushM (Pure t) (Event (Pure t) ())
70+ now t = Event $ guard . (t ==)
71+
69 push :: (a -> PushM (Pure t) (Maybe b)) -> Event (Pure t) a -> Event (Pure t) b
72 push :: (a -> PushM (Pure t) (Maybe b)) -> Event (Pure t) a -> Event (Pure t) b
70 push f e = Event $ memo $ \t -> unEvent e t >>= \o -> f o t
73 push f e = Event $ memo $ \t -> unEvent e t >>= \o -> f o t
71
74
src/Reflex/Spider/Internal.hs+8
@@ -415,6 +415,12 @@ subscribeAndReadNever = return (EventSubscription (return ()) eventSubscribedNev
415eventNever :: Event x a
415eventNever :: Event x a
416eventNever = Event $ const subscribeAndReadNever
416eventNever = Event $ const subscribeAndReadNever
417
417
418+eventNow :: Event x ()
419+eventNow = Event . const . pure $
420+ ( EventSubscription (return ()) eventSubscribedNever
421+ , Just ()
422+ )
423+
418eventFan :: (GCompare k, HasSpiderTimeline x) => k a -> Fan x k v -> Event x (v a)
424eventFan :: (GCompare k, HasSpiderTimeline x) => k a -> Fan x k v -> Event x (v a)
419eventFan !k !f = Event $ wrap eventSubscribedFan $ getFanSubscribed k f
425eventFan !k !f = Event $ wrap eventSubscribedFan $ getFanSubscribed k f
420
426
@@ -2729,6 +2735,8 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
2729 never = SpiderEvent eventNever
2735 never = SpiderEvent eventNever
2730 {-# INLINABLE constant #-}
2736 {-# INLINABLE constant #-}
2731 constant = SpiderBehavior . behaviorConst
2737 constant = SpiderBehavior . behaviorConst
2738+ {-# INLINABLE now #-}
2739+ now = pure . SpiderEvent $ eventNow
2732 {-# INLINE push #-}
2740 {-# INLINE push #-}
2733 push f = SpiderEvent . push (coerce f) . unSpiderEvent
2741 push f = SpiderEvent . push (coerce f) . unSpiderEvent
2734 {-# INLINE pushCheap #-}
2742 {-# INLINE pushCheap #-}