@@ -25,6 +25,8 @@ module Reflex.Dynamic
28 , constDyn
30 , constDyn
@@ -76,11 +78,9 @@ module Reflex.Dynamic
76 , distributeDMapOverDyn
78 , distributeDMapOverDyn
77 , distributeFHListOverDyn
79 , distributeFHListOverDyn
80 , getDemuxed
81 , getDemuxed
84 , mconcatDyn
84 , mconcatDyn
86 , splitDyn
86 , splitDyn
@@ -109,6 +109,14 @@ import Data.These
110import Debug.Trace
110import Debug.Trace
112+-- | Map a sampling function over a 'Dynamic'.
113+mapDynM :: forall t m a b. (Reflex t, MonadHold t m) => (forall m'. MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b)
114+mapDynM f d = buildDynamic (f =<< sample (current d)) $ pushAlways f (updated d)
116+-- | Flipped version of 'mapDynM'
117+forDynM :: forall t m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall m'. MonadSample t m' => a -> m' b) -> m (Dynamic t b)
118+forDynM d f = mapDynM f d
112-- | Create a new 'Dynamic' that only signals changes if the values actually
120-- | Create a new 'Dynamic' that only signals changes if the values actually
113-- changed.
121-- changed.
114holdUniqDyn :: (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a)
122holdUniqDyn :: (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a)
@@ -548,27 +556,11 @@ instance IsHList (a, b, c, d, e, f) where
548mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
556mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
549mapDyn f = return . fmap f
557mapDyn f = return . fmap f
551−-- | Map a sampling function over a 'Dynamic'. The sampling function will use the input 'Dynamic''s 'current' 'Behavior' until the first time its 'updated' 'Event' fires, at which point it will be invoked only once each time the 'Event' fires.
552−{-# DEPRECATED mapDynM "Consider using the Monad instance for Dynamic instead." #-}
553−mapDynM :: forall t m a b. (Reflex t, MonadHold t m) => (forall m'. MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b)
555− let e' = push (fmap Just . f :: a -> PushM t (Maybe b)) $ updated d
556− eb' = fmap constant e'
557− v0 = pull $ f =<< sample (current d)
558− bb' :: Behavior t (Behavior t b) <- hold v0 eb'
559− let b' = pull $ sample =<< sample bb'
560− return $ unsafeDynamic b' e'
562-- | Flipped version of 'mapDyn'.
559-- | Flipped version of 'mapDyn'.
563{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
560{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
564forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
561forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
565forDyn a = return . ffor a
562forDyn a = return . ffor a
567−-- | Flipped version of 'mapDynM'
568−{-# DEPRECATED forDynM "Consider using the Monad instance for Dynamic instead." #-}
569−forDynM :: forall t m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall m'. MonadSample t m' => a -> m' b) -> m (Dynamic t b)
570−forDynM d f = mapDynM f d
572-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
564-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
573-- of the tuple.
565-- of the tuple.
574{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}
566{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}