@@ -638,6 +638,8 @@ instance Reflex t => Bind (Event t) where
638instance Reflex t => Functor (Event t) where
638instance Reflex t => Functor (Event t) where
639 {-# INLINE fmap #-}
639 {-# INLINE fmap #-}
640 fmap f = fmapMaybe $ Just . f
640 fmap f = fmapMaybe $ Just . f
642+ x <$ e = fmapCheap (const x) e
642instance Reflex t => FunctorMaybe (Event t) where
644instance Reflex t => FunctorMaybe (Event t) where
643 {-# INLINE fmapMaybe #-}
645 {-# INLINE fmapMaybe #-}
@@ -956,12 +958,16 @@ mapAccumMaybeMDyn f z e = do
956 d' <- holdDyn z $ fmapMaybe fst e'
958 d' <- holdDyn z $ fmapMaybe fst e'
957 return (d', fmapMaybe snd e')
959 return (d', fmapMaybe snd e')
961+{-# INLINE accumB #-}
959accumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Behavior t a)
962accumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Behavior t a)
960accumB f = accumMaybeB $ \v o -> Just $ f v o
963accumB f = accumMaybeB $ \v o -> Just $ f v o
964+{-# INLINE accumMB #-}
961accumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Behavior t a)
965accumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Behavior t a)
962accumMB f = accumMaybeMB $ \v o -> Just <$> f v o
966accumMB f = accumMaybeMB $ \v o -> Just <$> f v o
967+{-# INLINE accumMaybeB #-}
963accumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
968accumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
964accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
969accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
970+{-# INLINE accumMaybeMB #-}
965accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
971accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
966accumMaybeMB f z e = do
972accumMaybeMB f z e = do
967 rec let e' = flip push e $ \o -> do
973 rec let e' = flip push e $ \o -> do
@@ -969,14 +975,17 @@ accumMaybeMB f z e = do
970 d' <- hold z e'
976 d' <- hold z e'
971 return d'
977 return d'
978+{-# INLINE mapAccumB #-}
972mapAccumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
979mapAccumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
973mapAccumB f = mapAccumMaybeB $ \v o -> bimap Just Just $ f v o
980mapAccumB f = mapAccumMaybeB $ \v o -> bimap Just Just $ f v o
981+{-# INLINE mapAccumMB #-}
974mapAccumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
982mapAccumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
975mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
983mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
984+{-# INLINE mapAccumMaybeB #-}
976mapAccumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
985mapAccumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
977mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
986mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
979−{-# INLINABLE mapAccumMaybeMB #-}
988+{-# INLINE mapAccumMaybeMB #-}
980mapAccumMaybeMB :: (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)
989mapAccumMaybeMB :: (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)
981mapAccumMaybeMB f z e = do
990mapAccumMaybeMB f z e = do
982 rec let e' = flip push e $ \o -> do
991 rec let e' = flip push e $ \o -> do
@@ -990,6 +999,7 @@ mapAccumMaybeMB f z e = do
991-- | Accumulate occurrences of an 'Event', producing an output occurrence each
1000-- | Accumulate occurrences of an 'Event', producing an output occurrence each
992-- time. Discard the underlying 'Accumulator'.
1001-- time. Discard the underlying 'Accumulator'.
1002+{-# INLINE mapAccum_ #-}
993mapAccum_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
1003mapAccum_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
994mapAccum_ f z e = do
1004mapAccum_ f z e = do
995 (_, result) <- mapAccumB f z e
1005 (_, result) <- mapAccumB f z e
@@ -997,6 +1007,7 @@ mapAccum_ f z e = do
998-- | Accumulate occurrences of an 'Event', possibly producing an output
1008-- | Accumulate occurrences of an 'Event', possibly producing an output
999-- occurrence each time. Discard the underlying 'Accumulator'.
1009-- occurrence each time. Discard the underlying 'Accumulator'.
1010+{-# INLINE mapAccumMaybe_ #-}
1000mapAccumMaybe_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
1011mapAccumMaybe_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
1001mapAccumMaybe_ f z e = do
1012mapAccumMaybe_ f z e = do
1002 (_, result) <- mapAccumMaybeB f z e
1013 (_, result) <- mapAccumMaybeB f z e
@@ -1004,6 +1015,7 @@ mapAccumMaybe_ f z e = do
1005-- | Accumulate occurrences of an 'Event', using a 'PushM' action and producing
1016-- | Accumulate occurrences of an 'Event', using a 'PushM' action and producing
1006-- an output occurrence each time. Discard the underlying 'Accumulator'.
1017-- an output occurrence each time. Discard the underlying 'Accumulator'.
1018+{-# INLINE mapAccumM_ #-}
1007mapAccumM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Event t c)
1019mapAccumM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Event t c)
1008mapAccumM_ f z e = do
1020mapAccumM_ f z e = do
1009 (_, result) <- mapAccumMB f z e
1021 (_, result) <- mapAccumMB f z e
@@ -1012,6 +1024,7 @@ mapAccumM_ f z e = do
1012-- | Accumulate occurrences of an 'Event', using a 'PushM' action and possibly
1024-- | Accumulate occurrences of an 'Event', using a 'PushM' action and possibly
1013-- producing an output occurrence each time. Discard the underlying
1025-- producing an output occurrence each time. Discard the underlying
1014-- 'Accumulator'.
1026-- 'Accumulator'.
1027+{-# INLINE mapAccumMaybeM_ #-}
1015mapAccumMaybeM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
1028mapAccumMaybeM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
1016mapAccumMaybeM_ f z e = do
1029mapAccumMaybeM_ f z e = do
1017 (_, result) <- mapAccumMaybeMB f z e
1030 (_, result) <- mapAccumMaybeMB f z e
@@ -1040,14 +1053,17 @@ zipListWithEvent f l e = do
1040 mapAccumMaybe_ f' l e
1053 mapAccumMaybe_ f' l e
1042-- | Assign a number to each occurence of the given 'Event', starting from 0
1055-- | Assign a number to each occurence of the given 'Event', starting from 0
1056+{-# INLINE numberOccurrences #-}
1043numberOccurrences :: (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Event t (b, a))
1057numberOccurrences :: (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Event t (b, a))
1044numberOccurrences = numberOccurrencesFrom 0
1058numberOccurrences = numberOccurrencesFrom 0
1046-- | Assign a number to each occurence of the given 'Event'
1060-- | Assign a number to each occurence of the given 'Event'
1061+{-# INLINE numberOccurrencesFrom #-}
1047numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
1062numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
1048numberOccurrencesFrom = mapAccum_ (\n a -> (n + 1, (n, a)))
1063numberOccurrencesFrom = mapAccum_ (\n a -> (n + 1, (n, a)))
1050-- | Assign a number to each occurence of the given 'Event'; discard the occurrences' values
1065-- | Assign a number to each occurence of the given 'Event'; discard the occurrences' values
1066+{-# INLINE numberOccurrencesFrom_ #-}
1051numberOccurrencesFrom_ :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t b)
1067numberOccurrencesFrom_ :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t b)
1052numberOccurrencesFrom_ = mapAccum_ (\n _ -> (n + 1, n))
1068numberOccurrencesFrom_ = mapAccum_ (\n _ -> (n + 1, n))