@@ -14,6 +14,7 @@
14{-# LANGUAGE TypeFamilies #-}
14{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE TypeOperators #-}
15{-# LANGUAGE TypeOperators #-}
16{-# LANGUAGE UndecidableInstances #-}
16{-# LANGUAGE UndecidableInstances #-}
17+{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
18-- | This module contains the Reflex interface, as well as a variety of
19-- | This module contains the Reflex interface, as well as a variety of
19-- convenience functions for working with 'Event's, 'Behavior's, and other
20-- convenience functions for working with 'Event's, 'Behavior's, and other
@@ -141,8 +142,6 @@ import Debug.Trace (trace)
141class ( MonadHold t (PushM t)
142class ( MonadHold t (PushM t)
142 , MonadSample t (PullM t)
143 , MonadSample t (PullM t)
143 , MonadFix (PushM t)
144 , MonadFix (PushM t)
145− , Functor (Behavior t)
146 , Functor (Dynamic t)
145 , Functor (Dynamic t)
147 , Applicative (Dynamic t) -- Necessary for GHC <= 7.8
146 , Applicative (Dynamic t) -- Necessary for GHC <= 7.8
148 , Monad (Dynamic t)
147 , Monad (Dynamic t)
@@ -507,9 +506,11 @@ instance Reflex t => Bind (Event t) where
507 join = coincidence
506 join = coincidence
509instance Reflex t => Functor (Event t) where
508instance Reflex t => Functor (Event t) where
510 fmap f = fmapMaybe $ Just . f
510 fmap f = fmapMaybe $ Just . f
512instance Reflex t => FunctorMaybe (Event t) where
512instance Reflex t => FunctorMaybe (Event t) where
513+ {-# INLINE fmapMaybe #-}
513 fmapMaybe f = push $ return . f
514 fmapMaybe f = push $ return . f
515-- | Never: @'zero' = 'never'@.
516-- | Never: @'zero' = 'never'@.
@@ -645,6 +646,7 @@ instance (Semigroup a, Reflex t) => Monoid (Event t a) where
645-- | Create a new 'Event' that occurs if at least one of the 'Event's in the
646-- | Create a new 'Event' that occurs if at least one of the 'Event's in the
646-- list occurs. If multiple occur at the same time they are folded from the left
647-- list occurs. If multiple occur at the same time they are folded from the left
647-- with the given function.
648-- with the given function.
649+{-# INLINE mergeWith #-}
648mergeWith :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
650mergeWith :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
649mergeWith f es = fmap (Prelude.foldl1 f . map (\(Const2 _ :=> Identity v) -> v) . DMap.toList)
651mergeWith f es = fmap (Prelude.foldl1 f . map (\(Const2 _ :=> Identity v) -> v) . DMap.toList)
@@ -655,6 +657,7 @@ mergeWith f es = fmap (Prelude.foldl1 f . map (\(Const2 _ :=> Identity v) -> v)
655-- | Create a new 'Event' that occurs if at least one of the 'Event's in the
657-- | Create a new 'Event' that occurs if at least one of the 'Event's in the
656-- list occurs. If multiple occur at the same time the value is the value of the
658-- list occurs. If multiple occur at the same time the value is the value of the
657-- leftmost event.
659-- leftmost event.
660+{-# INLINE leftmost #-}
658leftmost :: Reflex t => [Event t a] -> Event t a
661leftmost :: Reflex t => [Event t a] -> Event t a
659leftmost = mergeWith const
662leftmost = mergeWith const