@@ -103,6 +103,7 @@ module Reflex.Class
103 -- * Miscellaneous convenience functions
103 -- * Miscellaneous convenience functions
105 , MonadAdjust (..)
105 , MonadAdjust (..)
106 , sequenceDMapWithAdjust
107 , sequenceDMapWithAdjust
107 , sequenceDMapWithAdjustWithMove
108 , sequenceDMapWithAdjustWithMove
108 , mapMapWithAdjustWithMove
109 , mapMapWithAdjustWithMove
@@ -701,6 +702,8 @@ mergeWith = mergeWith' id
702{-# INLINE mergeWith' #-}
703{-# INLINE mergeWith' #-}
703mergeWith' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
704mergeWith' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
705+mergeWith' _ _ [] = never
706+mergeWith' f _ [e] = fmap f e
704mergeWith' f g es = fmap (Prelude.foldl1 g . map (\(Const2 _ :=> Identity v) -> f v) . DMap.toList)
707mergeWith' f g es = fmap (Prelude.foldl1 g . map (\(Const2 _ :=> Identity v) -> f v) . DMap.toList)
706 . DMap.fromDistinctAscList
709 . DMap.fromDistinctAscList
@@ -1023,6 +1026,9 @@ infixl 4 <@>
1023(<@) = tag
1026(<@) = tag
1024infixl 4 <@
1027infixl 4 <@
1029+runWithReplace :: MonadAdjust t m => m a -> Event t (m b) -> m (a, Event t b)
1030+runWithReplace = mapMWithReplace id id
1026-- | A 'Monad' that supports adjustment over time. After an action has been
1032-- | A 'Monad' that supports adjustment over time. After an action has been
1027-- run, if the given events fire, it will adjust itself so that its net effect
1033-- run, if the given events fire, it will adjust itself so that its net effect
1028-- is as though it had originally been run with the new value. Note that there
1034-- is as though it had originally been run with the new value. Note that there
@@ -1030,14 +1036,14 @@ infixl 4 <@
1030-- other side-effects) cannot be undone, so it is up to the instance implementer
1036-- other side-effects) cannot be undone, so it is up to the instance implementer
1031-- to determine what the best meaning for this class is in such cases.
1037-- to determine what the best meaning for this class is in such cases.
1032class (Reflex t, Monad m) => MonadAdjust t m | m -> t where
1038class (Reflex t, Monad m) => MonadAdjust t m | m -> t where
1033− runWithReplace :: m a -> Event t (m b) -> m (a, Event t b)
1039+ mapMWithReplace :: (a -> m b) -> (a' -> m b') -> a -> Event t a' -> m (b, Event t b')
1034 traverseDMapWithKeyWithAdjust :: GCompare k => (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> m (DMap k v', Event t (PatchDMap k v'))
1040 traverseDMapWithKeyWithAdjust :: GCompare k => (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> m (DMap k v', Event t (PatchDMap k v'))
1035 traverseDMapWithKeyWithAdjustWithMove :: GCompare k => (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMapWithMove k v) -> m (DMap k v', Event t (PatchDMapWithMove k v'))
1041 traverseDMapWithKeyWithAdjustWithMove :: GCompare k => (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMapWithMove k v) -> m (DMap k v', Event t (PatchDMapWithMove k v'))
1037instance MonadAdjust t m => MonadAdjust t (ReaderT r m) where
1043instance MonadAdjust t m => MonadAdjust t (ReaderT r m) where
1038− runWithReplace a0 a' = do
1044+ mapMWithReplace f g a0 a' = do
1039 r <- ask
1045 r <- ask
1040− lift $ runWithReplace (runReaderT a0 r) $ fmap (`runReaderT` r) a'
1046+ lift $ mapMWithReplace ((`runReaderT` r) . f) ((`runReaderT` r) . g) a0 a'
1041 traverseDMapWithKeyWithAdjust f dm0 dm' = do
1047 traverseDMapWithKeyWithAdjust f dm0 dm' = do
1042 r <- ask
1048 r <- ask
1043 lift $ traverseDMapWithKeyWithAdjust (\k v -> runReaderT (f k v) r) dm0 dm'
1049 lift $ traverseDMapWithKeyWithAdjust (\k v -> runReaderT (f k v) r) dm0 dm'
@@ -1094,6 +1100,8 @@ mergeWithCheap' f g = mergeWithFoldCheap' $ foldl1 g . fmap f
1095{-# INLINE mergeWithFoldCheap' #-}
1101{-# INLINE mergeWithFoldCheap' #-}
1096mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
1102mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
1103+mergeWithFoldCheap' _ [] = never
1104+mergeWithFoldCheap' f [e] = fmapCheap (f . (:|[])) e
1097mergeWithFoldCheap' f es =
1105mergeWithFoldCheap' f es =
1098 fmapCheap (f . (\(h : t) -> h :| t) . map (\(Const2 _ :=> Identity v) -> v) . DMap.toList)
1106 fmapCheap (f . (\(h : t) -> h :| t) . map (\(Const2 _ :=> Identity v) -> v) . DMap.toList)