on develop help sign in
Implement mergeWith' and mergeWithFoldCheap' with mergeInt instead of merge
commit2f998b73f1f98e4b0c61f0d98ebf3c95cb2a46f8 authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 1 Sep 2017, 14:29 (9 years ago) parent7c62738
1 file changed+8−8
src/Reflex/Class.hs+8−8
src/Reflex/Class.hs+8−8
@@ -731,10 +731,9 @@ mergeWith = mergeWith' id
731731
732732{-# INLINE mergeWith' #-}
733733mergeWith' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
734−mergeWith' f g es = fmap (Prelude.foldl1 g . map (\(Const2 _ :=> Identity v) -> f v) . DMap.toList)
735− . merge
736− . DMap.fromDistinctAscList
737− . map (\(k, v) -> Const2 k :=> v)
734+mergeWith' f g es = fmap (Prelude.foldl1 g . fmap f)
735+ . mergeInt
736+ . IntMap.fromDistinctAscList
738737 $ zip [0 :: Int ..] es
739738
740739-- | Create a new 'Event' that occurs if at least one of the 'Event's in the
@@ -968,6 +967,8 @@ mapAccumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)
968967mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
969968mapAccumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
970969mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
970+
971+{-# INLINABLE mapAccumMaybeMB #-}
971972mapAccumMaybeMB :: (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)
972973mapAccumMaybeMB f z e = do
973974 rec let e' = flip push e $ \o -> do
@@ -1186,10 +1187,9 @@ mergeWithCheap' f g = mergeWithFoldCheap' $ foldl1 g . fmap f
11861187{-# INLINE mergeWithFoldCheap' #-}
11871188mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
11881189mergeWithFoldCheap' f es =
1189− fmapCheap (f . (\(h : t) -> h :| t) . map (\(Const2 _ :=> Identity v) -> v) . DMap.toList)
1190− . merge
1191− . DMap.fromDistinctAscList
1192− . map (\(k, v) -> Const2 k :=> v)
1190+ fmapCheap (f . (\(h : t) -> h :| t) . IntMap.elems)
1191+ . mergeInt
1192+ . IntMap.fromDistinctAscList
11931193 $ zip [0 :: Int ..] es
11941194
11951195--------------------------------------------------------------------------------