@@ -21,9 +21,13 @@
2121{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
2222#endif
2323
24−-- | This module contains the Reflex interface, as well as a variety of
25−-- convenience functions for working with 'Event's, 'Behavior's, and other
26−-- signals.
24+-- |
25+-- Module:
26+-- Reflex.Class
27+-- Description:
28+-- This module contains the Reflex interface, as well as a variety of
29+-- convenience functions for working with 'Event's, 'Behavior's, and other
30+-- signals.
2731module Reflex.Class
2832 ( module Reflex.Patch
2933 -- * Primitives
@@ -133,8 +137,10 @@ module Reflex.Class
133137 -- * Unsafe functions
134138 , unsafeDynamic
135139 , unsafeMapIncremental
136− -- * 'FunctorMaybe'
137− , FunctorMaybe (..)
140+ -- * 'Filterable' convenience functions
141+ , FunctorMaybe -- fmapMaybe is purposely not exported from deprecated 'FunctorMaybe' and the new alias is exported instead
142+ , mapMaybe -- Re-exported for convenience
143+ , fmapMaybe
138144 , fforMaybe
139145 , ffilter
140146 , filterLeft
@@ -144,10 +150,11 @@ module Reflex.Class
144150 , ffor2
145151 , ffor3
146152 -- * Deprecated functions
147− , appendEvents
148− , onceE
149− , sequenceThese
153+ , switchPromptly
154+ , switchPromptOnly
155+ -- * "Cheap" functions
150156 , fmapMaybeCheap
157+ , mapMaybeCheap
151158 , fmapCheap
152159 , fforCheap
153160 , fforMaybeCheap
@@ -155,8 +162,6 @@ module Reflex.Class
155162 , tagCheap
156163 , mergeWithCheap
157164 , mergeWithCheap'
158− , switchPromptly
159− , switchPromptOnly
160165 -- * Slow, but general, implementations
161166 , slowHeadE
162167 ) where
@@ -193,7 +198,10 @@ import qualified Data.Some as Some
193198import Data.String
194199import Data.These
195200import Data.Type.Coercion
196−import Reflex.FunctorMaybe
201+import Data.Witherable (Filterable(..))
202+import qualified Data.Witherable as W
203+import Reflex.FunctorMaybe (FunctorMaybe)
204+import qualified Reflex.FunctorMaybe
197205import Reflex.Patch
198206import qualified Reflex.Patch.MapWithMove as PatchMapWithMove
199207
@@ -256,8 +264,7 @@ class ( MonadHold t (PushM t)
256264 -- | Create an 'Event' that will occur whenever the currently-selected input
257265 -- 'Event' occurs
258266 switch :: Behavior t (Event t a) -> Event t a
259− -- | Create an 'Event' that will occur whenever the input event is occurring
260− -- and its occurrence value, another 'Event', is also occurring
267+ -- | Create an 'Event' that will occur whenever the input event is occurring -- and its occurrence value, another 'Event', is also occurring
261268 coincidence :: Event t (Event t a) -> Event t a
262269 -- | Extract the 'Behavior' of a 'Dynamic'.
263270 current :: Dynamic t a -> Behavior t a
@@ -388,8 +395,8 @@ mapAccumMaybeMIncremental f z e = do
388395 return $ case result of
389396 (Nothing, Nothing) -> Nothing
390397 _ -> Just result
391− d' <- holdIncremental z $ fmapMaybe fst e'
392− return (d', fmapMaybe snd e')
398+ d' <- holdIncremental z $ mapMaybe fst e'
399+ return (d', mapMaybe snd e')
393400
394401slowHeadE :: (Reflex t, MonadHold t m, MonadFix m) => Event t a -> m (Event t a)
395402slowHeadE e = do
@@ -399,14 +406,14 @@ slowHeadE e = do
399406
400407-- | An 'EventSelector' allows you to efficiently 'select' an 'Event' based on a
401408-- key. This is much more efficient than filtering for each key with
402−-- 'fmapMaybe'.
409+-- 'mapMaybe'.
403410newtype EventSelector t k = EventSelector
404411 { -- | Retrieve the 'Event' for the given key. The type of the 'Event' is
405412 -- determined by the type of the key, so this can be used to fan-out
406413 -- 'Event's whose sub-'Event's have different types.
407414 --
408415 -- Using 'EventSelector's and the 'fan' primitive is far more efficient than
409− -- (but equivalent to) using 'fmapMaybe' to select only the relevant
416+ -- (but equivalent to) using 'mapMaybe' to select only the relevant
410417 -- occurrences of an 'Event'.
411418 select :: forall a. k a -> Event t a
412419 }
@@ -541,6 +548,15 @@ instance (Reflex t, Num a) => Num (Behavior t a) where
541548 negate = fmap negate
542549 signum = fmap signum
543550
551+instance (Num a, Reflex t) => Num (Dynamic t a) where
552+ (+) = liftA2 (+)
553+ (*) = liftA2 (*)
554+ abs = fmap abs
555+ signum = fmap signum
556+ fromInteger = pure . fromInteger
557+ negate = fmap negate
558+ (-) = liftA2 (-)
559+
544560instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
545561 a <> b = pull $ liftM2 (<>) (sample a) (sample b)
546562 sconcat = pull . fmap sconcat . mapM sample
@@ -550,22 +566,25 @@ instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
550566 times1p n = fmap $ times1p n
551567#endif
552568
553−-- | Flipped version of 'fmapMaybe'.
554−fforMaybe :: FunctorMaybe f => f a -> (a -> Maybe b) -> f b
555−fforMaybe = flip fmapMaybe
569+-- | Alias for 'mapMaybe'
570+fmapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b
571+fmapMaybe = mapMaybe
572+
573+-- | Flipped version of 'mapMaybe'.
574+fforMaybe :: Filterable f => f a -> (a -> Maybe b) -> f b
575+fforMaybe = flip mapMaybe
556576
557577-- | Filter 'f a' using the provided predicate.
558−-- Relies on 'fforMaybe'.
559−ffilter :: FunctorMaybe f => (a -> Bool) -> f a -> f a
560−ffilter f = fmapMaybe $ \x -> if f x then Just x else Nothing
578+ffilter :: Filterable f => (a -> Bool) -> f a -> f a
579+ffilter = W.filter
561580
562581-- | Filter 'Left's from 'f (Either a b)' into 'a'.
563−filterLeft :: FunctorMaybe f => f (Either a b) -> f a
564−filterLeft = fmapMaybe (either Just (const Nothing))
582+filterLeft :: Filterable f => f (Either a b) -> f a
583+filterLeft = mapMaybe (either Just (const Nothing))
565584
566585-- | Filter 'Right's from 'f (Either a b)' into 'b'.
567−filterRight :: FunctorMaybe f => f (Either a b) -> f b
568−filterRight = fmapMaybe (either (const Nothing) Just)
586+filterRight :: Filterable f => f (Either a b) -> f b
587+filterRight = mapMaybe (either (const Nothing) Just)
569588
570589-- | Left-biased event union (prefers left event on simultaneous
571590-- occurrence).
@@ -583,13 +602,18 @@ instance Reflex t => Bind (Event t) where
583602
584603instance Reflex t => Functor (Event t) where
585604 {-# INLINE fmap #-}
586− fmap f = fmapMaybe $ Just . f
605+ fmap f = mapMaybe $ Just . f
587606 {-# INLINE (<$) #-}
588607 x <$ e = fmapCheap (const x) e
589608
609+-- TODO Remove this instance
590610instance Reflex t => FunctorMaybe (Event t) where
591611 {-# INLINE fmapMaybe #-}
592− fmapMaybe f = push $ return . f
612+ fmapMaybe = mapMaybe
613+
614+instance Reflex t => Filterable (Event t) where
615+ {-# INLINE mapMaybe #-}
616+ mapMaybe f = push $ return . f
593617
594618-- | Never: @'zero' = 'never'@.
595619instance Reflex t => Plus (Event t) where
@@ -807,7 +831,7 @@ fanEither :: Reflex t => Event t (Either a b) -> (Event t a, Event t b)
807831fanEither e =
808832 let justLeft = either Just (const Nothing)
809833 justRight = either (const Nothing) Just
810− in (fmapMaybe justLeft e, fmapMaybe justRight e)
834+ in (mapMaybe justLeft e, mapMaybe justRight e)
811835
812836-- | Split the event into separate events for 'This' and 'That' values,
813837-- allowing them to fire simultaneously when the input value is 'These'.
@@ -819,7 +843,7 @@ fanThese e =
819843 that (That y) = Just y
820844 that (These _ y) = Just y
821845 that _ = Nothing
822− in (fmapMaybe this e, fmapMaybe that e)
846+ in (mapMaybe this e, mapMaybe that e)
823847
824848-- | Split the event into an 'EventSelector' that allows efficient selection of
825849-- the individual 'Event's.
@@ -998,14 +1022,16 @@ distributeListOverDynWith f = fmap (f . map (\(Const2 _ :=> Identity v) -> v) .
9981022difference :: Reflex t => Event t a -> Event t b -> Event t a
9991023difference = alignEventWithMaybe $ \case
10001024 This a -> Just a
1001− _ -> Nothing
1025+ _ -> Nothing
10021026
1027+-- | Zips two values by taking the union of their shapes and combining with the provided function.
1028+-- 'Nothing' values are dropped.
10031029alignEventWithMaybe :: Reflex t => (These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
1004−alignEventWithMaybe f ea eb =
1005− fmapMaybe (f <=< dmapToThese)
1006− $ merge
1007− $ DMap.fromList [LeftTag :=> ea, RightTag :=> eb]
1030+alignEventWithMaybe f ea eb = mapMaybe (f <=< dmapToThese) $
1031+ merge $ DMap.fromList [LeftTag :=> ea, RightTag :=> eb]
10081032
1033+-- | Produces an 'Event' that fires only when the input event fires with a 'DSum' key that
1034+-- matches the provided key.
10091035filterEventKey
10101036 :: forall t m k v a.
10111037 ( Reflex t
@@ -1023,7 +1049,10 @@ filterEventKey k kv' = do
10231049 Nothing -> Nothing
10241050 takeWhileJustE f kv'
10251051
1026−
1052+-- | "Factor" the input 'DSum' 'Event' to produce an 'Event' which
1053+-- fires when the 'DSum' key changes and contains both the value of the
1054+-- 'DSum' at switchover and an 'Event' of values produced by subsequent
1055+-- firings of the input 'Event' that do not change the 'DSum' key.
10271056factorEvent
10281057 :: forall t m k v a.
10291058 ( Reflex t
@@ -1073,26 +1102,94 @@ class Reflex t => Accumulator t f | f -> t where
10731102 mapAccumMaybe f = mapAccumMaybeM $ \v o -> return $ f v o
10741103 mapAccumMaybeM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (f a, Event t c)
10751104
1076−accumDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Dynamic t a)
1105+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1106+-- with the provided function. See 'foldDyn'.
1107+accumDyn
1108+ :: (Reflex t, MonadHold t m, MonadFix m)
1109+ => (a -> b -> a)
1110+ -> a
1111+ -> Event t b
1112+ -> m (Dynamic t a)
10771113accumDyn f = accumMaybeDyn $ \v o -> Just $ f v o
1078−accumMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Dynamic t a)
1114+
1115+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1116+-- with the provided 'PushM' action.
1117+accumMDyn
1118+ :: (Reflex t, MonadHold t m, MonadFix m)
1119+ => (a -> b -> PushM t a)
1120+ -> a
1121+ -> Event t b
1122+ -> m (Dynamic t a)
10791123accumMDyn f = accumMaybeMDyn $ \v o -> Just <$> f v o
1080−accumMaybeDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
1124+
1125+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1126+-- with the provided function, discarding 'Nothing' results.
1127+accumMaybeDyn
1128+ :: (Reflex t, MonadHold t m, MonadFix m)
1129+ => (a -> b -> Maybe a)
1130+ -> a
1131+ -> Event t b
1132+ -> m (Dynamic t a)
10811133accumMaybeDyn f = accumMaybeMDyn $ \v o -> return $ f v o
1082−accumMaybeMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
1134+
1135+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1136+-- with the provided 'PushM' action, discarding 'Nothing' results.
1137+accumMaybeMDyn
1138+ :: (Reflex t, MonadHold t m, MonadFix m)
1139+ => (a -> b -> PushM t (Maybe a))
1140+ -> a
1141+ -> Event t b
1142+ -> m (Dynamic t a)
10831143accumMaybeMDyn f z e = do
10841144 rec let e' = flip push e $ \o -> do
10851145 v <- sample $ current d'
10861146 f v o
10871147 d' <- holdDyn z e'
10881148 return d'
1089−mapAccumDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1149+
1150+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1151+-- with a function that both accumulates and produces a value to fire
1152+-- as an 'Event'. Returns both the accumulated value and an 'Event'.
1153+mapAccumDyn
1154+ :: (Reflex t, MonadHold t m, MonadFix m)
1155+ => (a -> b -> (a, c))
1156+ -> a
1157+ -> Event t b
1158+ -> m (Dynamic t a, Event t c)
10901159mapAccumDyn f = mapAccumMaybeDyn $ \v o -> bimap Just Just $ f v o
1091−mapAccumMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1160+
1161+-- | Similar to 'mapAccumDyn' except that the combining function is a
1162+-- 'PushM' action.
1163+mapAccumMDyn
1164+ :: (Reflex t, MonadHold t m, MonadFix m)
1165+ => (a -> b -> PushM t (a, c))
1166+ -> a
1167+ -> Event t b
1168+ -> m (Dynamic t a, Event t c)
10921169mapAccumMDyn f = mapAccumMaybeMDyn $ \v o -> bimap Just Just <$> f v o
1093−mapAccumMaybeDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1170+
1171+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event' with
1172+-- a function that both optionally accumulates and optionally produces
1173+-- a value to fire as a separate output 'Event'.
1174+-- Note that because 'Nothing's are discarded in both cases, the output
1175+-- 'Event' may fire even though the output 'Dynamic' has not changed, and
1176+-- the output 'Dynamic' may update even when the output 'Event' is not firing.
1177+mapAccumMaybeDyn
1178+ :: (Reflex t, MonadHold t m, MonadFix m)
1179+ => (a -> b -> (Maybe a, Maybe c))
1180+ -> a
1181+ -> Event t b
1182+ -> m (Dynamic t a, Event t c)
10941183mapAccumMaybeDyn f = mapAccumMaybeMDyn $ \v o -> return $ f v o
1095−mapAccumMaybeMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1184+
1185+-- | Like 'mapAccumMaybeDyn' except that the combining function is a
1186+-- 'PushM' action.
1187+mapAccumMaybeMDyn
1188+ :: (Reflex t, MonadHold t m, MonadFix m)
1189+ => (a -> b -> PushM t (Maybe a, Maybe c))
1190+ -> a
1191+ -> Event t b
1192+ -> m (Dynamic t a, Event t c)
10961193mapAccumMaybeMDyn f z e = do
10971194 rec let e' = flip push e $ \o -> do
10981195 v <- sample $ current d'
@@ -1100,18 +1197,42 @@ mapAccumMaybeMDyn f z e = do
11001197 return $ case result of
11011198 (Nothing, Nothing) -> Nothing
11021199 _ -> Just result
1103− d' <- holdDyn z $ fmapMaybe fst e'
1104− return (d', fmapMaybe snd e')
1200+ d' <- holdDyn z $ mapMaybe fst e'
1201+ return (d', mapMaybe snd e')
11051202
1203+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1204+-- with the provided function.
11061205{-# INLINE accumB #-}
1107−accumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Behavior t a)
1206+accumB
1207+ :: (Reflex t, MonadHold t m, MonadFix m)
1208+ => (a -> b -> a)
1209+ -> a
1210+ -> Event t b
1211+ -> m (Behavior t a)
11081212accumB f = accumMaybeB $ \v o -> Just $ f v o
1213+
1214+-- | Like 'accumB' except that the combining function is a 'PushM' action.
11091215{-# INLINE accumMB #-}
1110−accumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Behavior t a)
1216+accumMB
1217+ :: (Reflex t, MonadHold t m, MonadFix m)
1218+ => (a -> b -> PushM t a)
1219+ -> a
1220+ -> Event t b
1221+ -> m (Behavior t a)
11111222accumMB f = accumMaybeMB $ \v o -> Just <$> f v o
1223+
1224+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1225+-- with the provided function, discarding 'Nothing' results.
11121226{-# INLINE accumMaybeB #-}
1113−accumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
1227+accumMaybeB
1228+ :: (Reflex t, MonadHold t m, MonadFix m)
1229+ => (a -> b -> Maybe a)
1230+ -> a
1231+ -> Event t b
1232+ -> m (Behavior t a)
11141233accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
1234+
1235+-- | Like 'accumMaybeB' except that the combining function is a 'PushM' action.
11151236{-# INLINE accumMaybeMB #-}
11161237accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
11171238accumMaybeMB f z e = do
@@ -1120,16 +1241,42 @@ accumMaybeMB f z e = do
11201241 f v o
11211242 d' <- hold z e'
11221243 return d'
1244+
1245+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1246+-- with a function that both accumulates and produces a value to fire
1247+-- as an 'Event'. Returns both the accumulated value and an 'Event'.
11231248{-# INLINE mapAccumB #-}
1124−mapAccumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1249+mapAccumB
1250+ :: (Reflex t, MonadHold t m, MonadFix m)
1251+ => (a -> b -> (a, c))
1252+ -> a
1253+ -> Event t b
1254+ -> m (Behavior t a, Event t c)
11251255mapAccumB f = mapAccumMaybeB $ \v o -> bimap Just Just $ f v o
1256+
1257+-- | Like 'mapAccumB' except that the combining function is a 'PushM' action.
11261258{-# INLINE mapAccumMB #-}
1127−mapAccumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1259+mapAccumMB
1260+ :: (Reflex t, MonadHold t m, MonadFix m)
1261+ => (a -> b -> PushM t (a, c))
1262+ -> a
1263+ -> Event t b
1264+ -> m (Behavior t a, Event t c)
11281265mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
1266+
1267+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event' with
1268+-- a function that both optionally accumulates and optionally produces
1269+-- a value to fire as a separate output 'Event'. 'Nothing's are discarded.
11291270{-# INLINE mapAccumMaybeB #-}
1130−mapAccumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1271+mapAccumMaybeB
1272+ :: (Reflex t, MonadHold t m, MonadFix m)
1273+ => (a -> b -> (Maybe a, Maybe c))
1274+ -> a
1275+ -> Event t b
1276+ -> m (Behavior t a, Event t c)
11311277mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
11321278
1279+-- | LIke 'mapAccumMaybeB' except that the combining function is a 'PushM' action.
11331280{-# INLINE mapAccumMaybeMB #-}
11341281mapAccumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
11351282mapAccumMaybeMB f z e = do
@@ -1139,8 +1286,8 @@ mapAccumMaybeMB f z e = do
11391286 return $ case result of
11401287 (Nothing, Nothing) -> Nothing
11411288 _ -> Just result
1142− d' <- hold z $ fmapMaybe fst e'
1143− return (d', fmapMaybe snd e')
1289+ d' <- hold z $ mapMaybe fst e'
1290+ return (d', mapMaybe snd e')
11441291
11451292-- | Accumulate occurrences of an 'Event', producing an output occurrence each
11461293-- time. Discard the underlying 'Accumulator'.
@@ -1284,38 +1431,53 @@ infixl 4 <@
12841431-- Cheap Functions
12851432------------------
12861433
1434+-- | A "cheap" version of 'pushAlways'. See the performance note on 'pushCheap'.
12871435{-# INLINE pushAlwaysCheap #-}
12881436pushAlwaysCheap :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
12891437pushAlwaysCheap f = pushCheap (fmap Just . f)
12901438
1439+-- | A "cheap" version of 'mapMaybe'. See the performance note on 'pushCheap'.
1440+{-# INLINE mapMaybeCheap #-}
1441+mapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1442+mapMaybeCheap f = pushCheap $ return . f
1443+
1444+-- | An alias for 'mapMaybeCheap'
12911445{-# INLINE fmapMaybeCheap #-}
12921446fmapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1293−fmapMaybeCheap f = pushCheap $ return . f
1447+fmapMaybeCheap = mapMaybeCheap
1448+
12941449
1450+-- | A "cheap" version of 'fforMaybe'. See the performance note on 'pushCheap'.
12951451{-# INLINE fforMaybeCheap #-}
12961452fforMaybeCheap :: Reflex t => Event t a -> (a -> Maybe b) -> Event t b
1297−fforMaybeCheap = flip fmapMaybeCheap
1453+fforMaybeCheap = flip mapMaybeCheap
12981454
1455+-- | A "cheap" version of 'ffor'. See the performance note on 'pushCheap'.
12991456{-# INLINE fforCheap #-}
13001457fforCheap :: Reflex t => Event t a -> (a -> b) -> Event t b
13011458fforCheap = flip fmapCheap
13021459
1460+-- | A "cheap" version of 'fmap'. See the performance note on 'pushCheap'.
13031461{-# INLINE fmapCheap #-}
13041462fmapCheap :: Reflex t => (a -> b) -> Event t a -> Event t b
13051463fmapCheap f = pushCheap $ return . Just . f
13061464
1465+-- | A "cheap" version of 'tag'. See the performance note on 'pushCheap'.
13071466{-# INLINE tagCheap #-}
13081467tagCheap :: Reflex t => Behavior t b -> Event t a -> Event t b
13091468tagCheap b = pushAlwaysCheap $ \_ -> sample b
13101469
1470+-- | A "cheap" version of 'mergeWithCheap'. See the performance note on 'pushCheap'.
13111471{-# INLINE mergeWithCheap #-}
13121472mergeWithCheap :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
13131473mergeWithCheap = mergeWithCheap' id
13141474
1475+-- | A "cheap" version of 'mergeWithCheap''. See the performance note on 'pushCheap'.
13151476{-# INLINE mergeWithCheap' #-}
13161477mergeWithCheap' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
13171478mergeWithCheap' f g = mergeWithFoldCheap' $ foldl1 g . fmap f
13181479
1480+-- | A "cheap" version of 'mergeWithFoldCheap''. See the performance note on 'pushCheap'.
13191481{-# INLINE mergeWithFoldCheap' #-}
13201482mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
13211483mergeWithFoldCheap' f es =
@@ -1328,28 +1490,6 @@ mergeWithFoldCheap' f es =
13281490-- Deprecated functions
13291491--------------------------------------------------------------------------------
13301492
1331−-- | Create a new 'Event' that occurs if at least one of the supplied 'Event's
1332−-- occurs. If both occur at the same time they are combined using 'mappend'.
1333−{-# DEPRECATED appendEvents "If a 'Semigroup a' instance is available, use 'mappend'; otherwise, use 'alignWith (mergeThese mappend)' instead" #-}
1334−appendEvents :: (Reflex t, Monoid a) => Event t a -> Event t a -> Event t a
1335−appendEvents = alignWith $ mergeThese mappend
1336−
1337−-- | Alias for 'headE'
1338−{-# DEPRECATED onceE "Use 'headE' instead" #-}
1339−onceE :: MonadHold t m => Event t a -> m (Event t a)
1340−onceE = headE
1341−
1342−-- | Run both sides of a 'These' monadically, combining the results.
1343−{-# DEPRECATED sequenceThese "Use bisequenceA or bisequence from the bifunctors package instead" #-}
1344−#ifdef USE_TEMPLATE_HASKELL
1345−{-# ANN sequenceThese "HLint: ignore Use fmap" #-}
1346−#endif
1347−sequenceThese :: Monad m => These (m a) (m b) -> m (These a b)
1348−sequenceThese t = case t of
1349− This ma -> fmap This ma
1350− These ma mb -> liftM2 These ma mb
1351− That mb -> fmap That mb
1352−
13531493{-# DEPRECATED switchPromptly "Use 'switchHoldPromptly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
13541494switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
13551495switchPromptly = switchHoldPromptly